Beginner's Sprite Tutorial

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's Sprite Tutorial

Post by RMartins »

I'm assuming you want an 8px char.
Does it need to be 16px width ?

I have 2 simple ones, with 16px character, in 24px width.
Image
and
Image

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

Re: Beginner's Sprite Tutorial

Post by R-Tape »

They look a bit too good for purposes here! They are 2 sexy looking sprites.

Could you post the frames here and perhaps I can modify the blob?
redballoon
Manic Miner
Posts: 390
Joined: Sun Nov 12, 2017 3:54 pm

Re: Beginner's Sprite Tutorial

Post by redballoon »

Yeah is it possible to see the frames for the 2nd one?
The 1st looks sound but the right leg in the 2nd one looks a bit weird at times. It could just be trying to view a small image in my phone, though.
User avatar
Rorthron
Dynamite Dan
Posts: 1644
Joined: Sun Nov 12, 2017 10:35 pm

Re: Beginner's Sprite Tutorial

Post by Rorthron »

R-Tape wrote: Fri Dec 29, 2017 4:44 am I agree the walk looks weird.
I think it is because of the first (standing) frame and the frame after it.

In the standing frame the two legs do not fully overlap, and in the following frame the two feet are drawn differently, so that the forward foot is the left one. It creates the impression that only the left leg makes forwards steps. If both feet overlapped in the middle frame, so they looked like only one foot, and the stepping frames made the left and right feet look the same, the steps would look a little better (though it would then be inconsistent with the perspective on the face).
RMartins wrote: Fri Dec 29, 2017 4:58 am I'm assuming you want an 8px char.
Does it need to be 16px width ?

I have 2 simple ones, with 16px character, in 24px width.
Image
and
Image

Interested ?
Nice sprites!
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's Sprite Tutorial

Post by RMartins »

Here are Zoom versions of them.

Image

And
Image

I also have the SevenUp Editor .SEV files somewhere in my drive, I'll have a look and post them when found.
R-Tape wrote: Fri Dec 29, 2017 4:44 am ...
Or even better, could someone improve the animation of this blob? I like the idea of showing how a walking animation can be done simply.
I could try that, when I have a half an hour or so free. :)
redballoon wrote: Fri Dec 29, 2017 10:41 am ...
The 1st looks sound but the right leg in the 2nd one looks a bit weird at times. It could just be trying to view a small image in my phone, though.
There is something there yes, but I believe there isn't much that can be done about it, without looking funny, or having to change the whole sprite.

The issue you see is related with a bunch of pixels that are together on the left leg, when it's up in front.
It comes out as a brighter spot due to that, and that's what makes it feel a bit odd.

But if we remove those pixels, it seems the leg never crossed over, or the right leg might seem too bulky.

Maybe there are better solutions, but it's not easy at this size, in my opinion.
but feel free to change or update them, they can always be improved.

Thank you for all the positive comments, for my first walk animation studies, done quite a few months ago. ;)
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's Sprite Tutorial

Post by RMartins »

OK here are the SevenUp .SEV files.

WalkAnim-Study.sev

WalkAnim-Study3F.sev

You know the drill, after loading the files, just use cursor keys to animate the frames.

You can move the first anim sprites to be centered on a char boundary, since currently it's centered between 2 chars.

After taking a new look on the second anim, I'm sure it can be improved, by making the first stance after center position, to have a slighter larger gap between both legs.
You can also notice that both do not have arms yet.

Well, they were my first walk anims, what can I say, not perfect. :shock:

The one in my Avatar is a lot better, but also easier, with more pixels to shuffle :D
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Beginner's Sprite Tutorial

Post by Ast A. Moore »

Code: Select all

	ld b,(hl)	;get table address spritegraphic0, spritegraphic1 etc in BC
	ld l,c
	ld h,b
H (and L, incidentally) can be loaded directly from (HL):

Code: Select all

	ld h,(hl)
	ld l,c
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.
User avatar
Morkin
Bugaboo
Posts: 3250
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Beginner's Sprite Tutorial

Post by Morkin »

Nice thread this. Finally got round to having a decent look at this as I still haven't managed to write a decent pixel-based sprite routine.

In the Balachor games the sprite moved 4 pixels at a time, so I thought I may as well store X & Y co-ordinates as character co-ordinates 0-31, or 0-22. I did that mainly because I had previously been used to PRINT AT in BASIC.

I did a bit of experimentation with smoother movement, so it made sense for the Y-coordinate (vertical) to be a pixel co-ordinate of 0-192. But I still had the X-coordinate (horizontal) as 0-31, as I figured this was the only precision needed for horizontal screen addresses.

I didn't even consider storing the X co-ordinate as 0-255, and getting both the screen address and the sprite animation frame from that. I guess that's a more standard (and probably more sensible!) approach. I had the sprite animation frame as a separate variable.
My Speccy site: thirdharmoniser.com
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Beginner's Sprite Tutorial

Post by Ast A. Moore »

Morkin wrote: Fri Dec 29, 2017 2:59 pm it made sense for the Y-coordinate (vertical) to be a pixel co-ordinate of 0-192. But I still had the X-coordinate (horizontal) as 0-31, as I figured this was the only precision needed for horizontal screen addresses.

I didn't even consider storing the X co-ordinate as 0-255, and getting both the screen address and the sprite animation frame from that. I guess that's a more standard (and probably more sensible!) approach.
Even that isn’t enough when you’re dealing with fractional coordinates and sprites moving smoothly beyond the edges of the screen. Some clever trickery is required for that.
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.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's Sprite Tutorial

Post by RMartins »

Ok, I tried a couple of revisions ...

First I tried to add 2 steps instead of one, in 8 frames, which is doable, but since in this case we only want to advance 8 pixels, steps need to be small, which implies feet need to be small.

Image

But I did not like the outcome ... looks like "Miss Bob" in high heels :D

Hence I reverted back to a single step, which gave me a lot more control.
Image

Now I like this, but there is a catch.
If you repeat this, you will see that the back leg seems to drag, this is normal, because it's the animation of a single step, to a stop, so back leg has to slow down ... to a stop.

For 2 steps, we need the last 4 frames, to move the back leg a lot faster, since it's swinging to take the lead.
This is required, to make it look natural, i.e. we need to swap the last few frames to stop, or to keep walking.

I don't have more time now, to make the full walk version, 4 more frames.
The body movement, will be identical or similar, but the back leg, needs to speed up, and end half bent, to continue.

I hope it helps.

UPDATE:
Here is a longer repeating version, where it looks like he is limping, as I mentioned before.
Image
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Beginner's Sprite Tutorial

Post by Seven.FFF »

I've now got as far as preshifting in my tutorial series, in a bit of a scattershod way.

Happy new year!
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Wall_Axe
Manic Miner
Posts: 491
Joined: Mon Nov 13, 2017 11:13 pm

Re: Beginner's Sprite Tutorial

Post by Wall_Axe »

you seem to have gotten the multicolor sprite moving smoothly right to left as well as up and down
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Beginner's Sprite Tutorial

Post by MrPixel »

is this BASIC or Machine code. if it's the latter, would ZEUS be good?
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: Beginner's Sprite Tutorial

Post by R-Tape »

MrPixel wrote: Sat Mar 24, 2018 10:29 pm is this BASIC or Machine code. if it's the latter, would ZEUS be good?
Which bit? The sprite code I posted on page 3 is assembly language that the ZX-Spin 0.666 assembler translates into machine code. There are no nobs & whistles so I think any assembler including ZEUS should be fine with it :-)
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Beginner's Sprite Tutorial

Post by MrPixel »

i get errors whenever i attempt to call a sprite.
Callsprite drawsprite and deletesprite all get errors

even with the call command
User avatar
PeterJ
Site Admin
Posts: 6852
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Beginner's Sprite Tutorial

Post by PeterJ »

[mention]MrPixel[/mention] have you got your simple example working in Zeus first? Zeus has what I call configuration options before the code. [mention]Seven.FFF[/mention] explains it very well in his tutorial. Get that working first.

Did you write that previous piece of code yourself and do you have coding experience in assembler from your Atari time?
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Beginner's Sprite Tutorial

Post by MrPixel »

PeterJ wrote: Tue Mar 27, 2018 6:50 pm @MrPixel have you got your simple example working in Zeus first? Zeus has what I call configuration options before the code. @Seven.FFF explains it very well in his tutorial. Get that working first.

Did you write that previous piece of code yourself and do you have coding experience in assembler from your Atari time?
no, from a different section of this site. and i used zx spin 0.666

really wish there was a hot key to assemble
User avatar
PeterJ
Site Admin
Posts: 6852
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Beginner's Sprite Tutorial

Post by PeterJ »

OK. So I would get a small example working in Zeus, then move on to the bigger stuff like sprites. As others have said the Spectrum does not have Sprites, it's just code which tries to replicate what other machines did in hardware. Get a simple example working in your development environment of choice then move on. As mentioned the various documents, websites and books others have linked you to should get you started.
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Beginner's Sprite Tutorial

Post by Seven.FFF »

That version of Spin has been abandonware for at least 11 years, so it's really unlikely there's going to be any more changes to make it easier to user. Dunny is an ace developer, but he's moved onto other projects long ago.

It would probably help you to use something actively developed. To contrast with Spin, In the 15 months I've been using Zeus I have 110 old versions saved in my archive. I honestly don't think it's an exaggeration to say that about 70% of those have workflow improvements, new features, etc resulting from my own feedback to Simon, and I'm only one of many people using the tool. The Windows Z80 cross-platform version has been developed on an almost a daily basis for the last ten years, and the design draws directly from the native Spectrum Zeus in the early 80s, and even older 8080 versions back to 1977.

Which is not to say that you have to use Zeus, by any means! Everyone has their favourite tools that feel right and suit their workflow, and nobody's making them use anything else. But if you're picking a new tool without any history or preconceptions, it seems a shame to hobble yourself right from the get go.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Beginner's Sprite Tutorial

Post by Seven.FFF »

deletesprite, movesprite and drawsprite are from [mention]R-Tape[/mention]'s tutorial in the first post of this topic, not my blog, so I can't offer any specific advice. What [mention]PeterJ[/mention] says is sound sense - build the foundations then work up from there.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
PeterJ
Site Admin
Posts: 6852
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Beginner's Sprite Tutorial

Post by PeterJ »

[mention]Seven.FFF[/mention] apart from in your tutorial are there any documents that explains the configuration bits you put before the code?

I suppose I have always used Pasmo because you don't need all that extra stuff, but I should spend some time on Zeus especially as it has an.emulator built in..
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Beginner's Sprite Tutorial

Post by Seven.FFF »

PeterJ wrote: Tue Mar 27, 2018 7:52 pm [mention]Seven.FFF[/mention] apart from in your tutorial are there any documents that explains the configuration bits you put before the code?
Yes, for sure. The documentation is distributed on a non-linear fashion between here and here.

For a quick start, if you go File >> New ZX Spectrum (48K) you get a commented template. But let's see. This is what I consider to be the minimum configuration for a new project:

Code: Select all

zeusemulate "48K"
The machine type and feature set to emulate. Corresponds to the options in the dropdown. "48K" or "128K' would be the primary machine choices. Things like "ULA" or "NOROM" would be typical features you could add as a comma-separated parameter. If you pick an option that doesn't exist, and assemble, it will tell you what the choices are.

A lot of the Zeus options can be specified in the UI or in code. Doing it in the UI is obviously simpler and more intuitive, but doing it in the code has the advantage of being able to open, assemble and run multiple projects without having to tweak settings.

Code: Select all

zoLogicOperatorsHighPri = false
If you're compiling pasmo code you'd want to set this to true, as pasmo it's own strange operator precedence rules. Having this not set to match the code you're assembling is a major cause of errors, so I always like to put this into my own projects so I reset back to a good known configuration.

This is also corresponds to one of the many checkboxes on the Config tab.

Code: Select all

zoSupportStringEscapes  = false
Just my personal preference; lets you write paths with single backslashes instead of double ones. You don't need to specify it at all, really.

Code: Select all

Zeus_PC  = $nnnn
Stack equ $nnnn
Tells the emulator what PC and SP should be, right at the entry point. Unlike most emulators, Zeus boot the machine and phantom-type LOAD "" command. Instead it loads the initial machine state into memory and magically makes your assembled bytes appear in memory at the correct place(s), before jumping to your entry point. To do this, at the very least it needs to know what PC and SP are.

Conceptially, it's more like what happens at the point you finish loading a .z80 or .sna shapshot. The entire state of the machine is restored, before jumping to the entry point.

There are also other directives to set the registers, interrupt mode and enabled state, current 128K page, etc.

Instead of Zeus_PC you can also use the pasmo syntax of END $nnnn at the end of your code. For pasmo, that is an instruction to put a RANDOMIZE USR nnnnn command in the basic loader; for Zeus, it's an instruction for the emulator where to put the entry point.

It might seem like a pointless distinction, but having code injected directly makes 128K development a breeze - literally all eight 16K pages (or in the case of the Spectrum Next, all 223 8K pages!!) are in memory and ready to use right from the getgo, without the user having to write code to export them and merge them with a multipage loader.

Code: Select all

org $nnnn
Same as almost every assembler. Tells the assembler what address to put the next instruction. Often people only have one org at the beginnning, but you're able to write things like

Code: Select all

org zeuspage(7)
which will assemble the following code to $2C000. $2C000-$2FFFF is the 24-bit address that 128K page 7 permanently lives at, in the Zeus assembler and emulator. Doing a standard address page by writing to I/O port $7FFD would page page 7 in at $C000-$FFFF as well as $2C000-$2FFFF. The CPU only knows about the addresses between $0000-$FFFF, only having got a 16-bit address bus. But Zeus has it all in there, and keeps track of it. Other emulators do as well, of course, but having programmatic control over everything in both the assembler and emulator is pretty sweet, espectially for RAD stuff.

Code: Select all

output_z80"..\bin\blah.z80", $0000, EntryPoint
output_sna"..\bin\blah.sna", $0000, EntryPoint
output_tap"..\bin\blah.tap", "LoaderProgramName", "Comment", StartAddress, BytesToSave, 2, EntryPoint
output_tzx "..\bin\blah.tzx", "LoaderProgramName", "Comment", StartAddress, BytesToSave, 2, EntryPoint
Makes standard snapshot or tape (mode 2) files.

Where this gets interesting is the 128K/sparse memory scatterloader (mode 3) tape files, for example:

Code: Select all

output_tap"..\bin\blah.tap", "LoaderProgramName", "Comment", StartAddressOfBlock, BytesOfBlockToSave, 3, EntryPoint, BorderColours
output_tap_block "..\bin\blah.tap",StartAddressOfSecondBlock, BytesOfSecondBlockToSave
output_tap_block "..\bin\blah.tap",StartAddressOfThirdBlock, BytesOfThirdBlockToSave
The block addresses are 24-bit, so specifying $2C000, $2000 for example would load the first half of 128K page 7 directly into page 7. It's handled automatically - all the end user sees is the tape loading, while Zeus's custom loader code would do the necessary paging and copying to stuff everything into the right place.

If there's a loading screen at $4000-$5AFF (loaded with something like this):

Code: Select all

import_bin "loading.scr", $4000
then that gets progressively loaded in linear order (compensating for screen thirds) during the load of the rest of the data, like Halls of the Things did back in the day.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Beginner's Sprite Tutorial

Post by Ralf »

I believe we all need some good article about this Zeus ;)

It's seems that it became a serious player among crossassemblers quite recently.
It was always Sjasm or Pasmo before. Okay, maybe not always but last 10 years which seems like always ;)

I'm personally not up to date. When I hear Zeus I think about this thing from 1983 ;)
https://spectrumcomputing.co.uk/index.p ... 96&id=9010
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Beginner's Sprite Tutorial

Post by Seven.FFF »

Just to give a little teaser about another one of my fav Zeus features, I have a USB cable running into to my Spectrum Next, which has an integrated 2Mbps serial port. At the click of a button, Zeus assembles code, loads it down the wire into memory, and executes at the entry point.

It has a command line interface, so by typing my own commands I can list memory, do pokes, write to ports, reset the machine, disassemble any address (including 128K pages that aren't even currently paged in) with the source lines next to them, import files from disk on the PC into memory, and export memory blocks to disk on the PC.

Pretty much what any emulator debugger does - except that none of the emulators for the Next are fully functional yet, and the bits that are functional don't behave the same as they do on the real hardware.

You could get this running on a real Spectrum with a serial or parallel interface too, pretty easily (with some input from Simon).
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
PeterJ
Site Admin
Posts: 6852
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Beginner's Sprite Tutorial

Post by PeterJ »

[mention]R-Tape[/mention]. Is there any chance you could do versions of your examples to cover up and down from here please:

viewtopic.php?f=6&t=2575
Post Reply