Beginner's Sprite Tutorial

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
R-Tape
Site Admin
Posts: 1406
Joined: Thu Nov 09, 2017 11:46 am

Re: Beginner's Sprite Tutorial

Post by R-Tape » Sat Dec 23, 2017 11:42 pm

Cheers Bob & Mat,

I agree about the masking, better in binary, but also a diagram explaining why the xcor cycles 0-7 and why we mask them would be a good idea.

I've still Xmas shopping to do, might not get round to it tomorrow.
0 x

User avatar
PeterJ
Site Admin
Posts: 689
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Beginner's Sprite Tutorial

Post by PeterJ » Sun Dec 24, 2017 7:36 am

I've still Xmas shopping to do, might not get round to it tomorrow.
Don't get anything too big for me Dave!
0 x

User avatar
R-Tape
Site Admin
Posts: 1406
Joined: Thu Nov 09, 2017 11:46 am

Re: Beginner's Sprite Tutorial

Post by R-Tape » Sun Dec 24, 2017 3:55 pm

PeterJ wrote:
Sun Dec 24, 2017 7:36 am
Don't get anything too big for me Dave!
I hope you like those chocolates shaped liked shellfish, I've got a box left over from last year :-p
0 x

User avatar
MatGubbins
Manic Miner
Posts: 383
Joined: Mon Nov 13, 2017 11:45 am
Location: Kent, UK

Re: Beginner's Sprite Tutorial

Post by MatGubbins » Sun Dec 24, 2017 3:59 pm

R-Tape wrote:
Sun Dec 24, 2017 3:55 pm
PeterJ wrote:
Sun Dec 24, 2017 7:36 am
Don't get anything too big for me Dave!
I hope you like those chocolates shaped liked shellfish, I've got a box left over from last year :-p
But they were given to you from someone else that had them left over from the year before that! They must be Vintage!
1 x
Bomb Munchies Ver1930 17th Nov 2017 (look for the blue download box ) If you get a time-out message and live in the UK then try after 9pm-3am.
Send me a PM and I can email it to you too. Kent, UK

User avatar
bob_fossil
Dizzy
Posts: 98
Joined: Mon Nov 13, 2017 6:09 pm

Re: Beginner's Sprite Tutorial

Post by bob_fossil » Sun Dec 24, 2017 5:50 pm

Been playing around with R-Tape's posted source today and managed to knock this up with z88dk. The main loop is in C but the sprite erasing and drawing is all in assembly.

Image

All the graphics I've done so far have been basic block printing so having some example code to work from has been helpful to see how animated sprites works with the 'interesting' Spectrum screen layout - so thanks again for doing this!
1 x

Wall_Axe
Microbot
Posts: 155
Joined: Mon Nov 13, 2017 11:13 pm

Re: Beginner's Sprite Tutorial

Post by Wall_Axe » Sun Dec 24, 2017 6:00 pm

how are you avoiding flickering?
also could you give a verbal description of the erasing, because an 8x8 sprite could be in 4 atrributes at once, are you basically erasing all 4 close attributes every time?
0 x

User avatar
Seven.FFF
Manic Miner
Posts: 254
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Beginner's Sprite Tutorial

Post by Seven.FFF » Sun Dec 24, 2017 6:09 pm

There's no flickering because the ULA draws the entire screen sequentially, 50 times a second. If, in between those 50th second points, you write different values into the display memory multiple times (blank, redraw, blank, redraw, etc), the ULA will just draw the final result of that when it comes to the next drawing time.

It’s a bit like a strobe light flashing 50 times a second. Someone runs fast, but the strobe doesn’t capture all the movement, so you see big jumps in between. The movement is still happening, but you only see snapshots at regular intervals.

Everyone is used to flickering in basic because printing happens an awful lot slower. Erasing a character and reprinting it wouldn't happen in the same 1/50th second frame. The ROM is trying to do a lot of whole bunch of operating system stuff in every frame, not just printing, and none of it is particularly optimised for speed.
Last edited by Seven.FFF on Sun Dec 24, 2017 6:27 pm, edited 3 times in total.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

dfzx
Dizzy
Posts: 83
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Beginner's Sprite Tutorial

Post by dfzx » Sun Dec 24, 2017 6:20 pm

Use a hollow box graphic, not a filled one. That black smear going down your first image isn't at all clear. Maybe add a grid on 8 pixel boundaries so it's clearer that there's 3 bytes of width, not 2. It took me a while to work out why the bottom block of the graphic has a white line down the right edge.

You should probably define the term "preshifted" rather than just using it as if the reader is expected to know what it means.

The term "therefore each sprite is 48 bytes" might be better as "therefore each preshifted position of the sprite is 48 bytes".

Use more meaningful labels. I presume "xcor" is an abbreviation of "X coordinate"? Make it, say, "x_position". I don't know what "delp" might be an abbreviation of.

I don't think the LD BC,(xcor) is helpful at this level, even with the comment. Load B and C separately.


Otherwise, very good. I think a better graphic which more clearly describes how the preshifted sprite gets put into the bytes of the display would help. If someone hasn't grasped the concept of what you're doing I don't think reading that code will help them. Once they have grasped it, I think it should be clear.
1 x

User avatar
Ast A. Moore
Manic Miner
Posts: 589
Joined: Mon Nov 13, 2017 3:16 pm

Re: Beginner's Sprite Tutorial

Post by Ast A. Moore » Sun Dec 24, 2017 8:30 pm

Wall_Axe wrote:
Sun Dec 24, 2017 6:00 pm
how are you avoiding flickering?
The routine takes very little time and is completed entirely while the ULA is drawing the top border. By the time the beam reaches the active screen area, all the drawing and redrawing had long been finished. Hence, no flickering.

If you introduce a delay after the HALT, you can make the sprite flicker, or disappear entirely:

Code: Select all

	ld bc,$220
wait	dec bc
	ld a,b
	or c
	jp nz,wait
Feel free to play around with the value passed into BC.

To visualize where the electron beam is during code execution, it’s a good idea to changed the border color for that period. Modify the main loop as shown below, and you’ll see what I mean.

Code: Select all

main:	halt		

	ld bc,$220
wait	dec bc
	ld a,b
	or c
	jp nz,wait
			
	xor a		;border black
	out (254),a

	call deletesprit
	call movesprite	
	call drawsprite	

	ld a,7		;border white
	out (254),a

	jr main	
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

Wall_Axe
Microbot
Posts: 155
Joined: Mon Nov 13, 2017 11:13 pm

Re: Beginner's Sprite Tutorial

Post by Wall_Axe » Sun Dec 24, 2017 8:36 pm

ohhh theres a halt, so the sprites are drawn when the raster beam is at the top, ok thanks
0 x

Post Reply