Something dawned on me earlier. I love it when that happens. It was such a simple thing. So much so that I’m amazed I haven’t thought of it before.
My movement and drawing code sit independent of one another. First I call the code to move a sprite with move(sprite), then I immediately call the code to draw it to screen with draw(sprite).
The effect has always been satisfactory but when you want to move a sprite that actually walks rather than glides (as with a space alien or starship) it leaves a bit to be desired. You wind up with the effect that the walking sprite is actually gliding along the game canvas whilst going through his motions. Michael Jackson style.
But then it occured to me that I could simply change the order of events to have the sprite’s x, y co-ordinates incremented on every frame bump. So I moved the call to move(sprite) to sit within draw(sprite) at the exact point the frames are changed.
The end result is that the sprite only physically moves on screen when the animation permits it. Hey ho, my characters are walking properly.
I also introduced a new sprite – the Zombie.
Over time I will add collision and some special effects.
You can check the working code here: www.wilfscorner.co.uk/sandpit/1/wizard4.php
If the content doesn’t load for you first time please reload the page.