I’ve rendered a tile map and a tank on a screen in canvas:
http://www.exeneva.com/html5/movingTankExample/
However, you’ll notice that the tank’s animation movement (moving tracks) are regularly occurring. How would you change it so that the movement of the tank tracks occurs only when the tank is moved? Note that there is no physics at the moment.
your
startUpfunction is callingdrawScreenevery 100 ms where the tank movement gets animated. You need to extract the animation logic fromdrawScreeninto its own function, e.g.animateMovementand call it from youronkeydownhandler.Something like:
Put this just before your
drawScreenfunction and call it from yourdocument.onkeydownhandler just after you calldrawScreen. Obviously, you will also need to remove the animation code from yourdrawScreenfunction: