Game ControllerGame controller is very easy to make. You knew about Capturing Key and simple animation, then you can make game controller very fast. The first, you need to make moving function; moving.xpos += 5; moving.left = moving.xpos; setTimeout ("functionName", 30) moving.xpos -=5; moving.left = moving.xpos; setTimeout ("functionName", 30) moving.ypos -=5; moving.top = moving.ypos; setTimeout ("functionName", 30) moving.ypos +=5; moving.top = moving.ypos; setTimeout ("functionName", 30) You knew these functions. Now you need to determine what keys you use to move object. If you don't know key code go to key chapter and get the codes. I use arrow keys; var code = window.event.keyCode if (code == 39 && !moving.move) { moving.move = 1 move(); } if (code == 40 && !moving.move2) { moving.move2 = 1 move2(); } if (code == 37 && !moving.move3) { moving.move3 = 1 move3(); } if (code == 38 && !moving.move4) { moving.move4 = 1 move4(); } Move1 or move2 is function name. You know about moving.functionName script I think. And here is the key up script; var code = window.event.keyCode if (code == 39) {moving.move = 0} if (code == 40) {moving.move2 = 0} if (code == 37) {moving.move3 = 0} if (code == 38) {moving.move4 = 0} Now you made your game controller.
|