TouchInput & keydownhandler
Hi, I'm making a top-to-bottom shooter where you control a ship and dodge asteroids.
I've really been struggling to add touch support to move the ship up and down. I've also done a lot of searching around for youtube tutorials, but this is the best I could do.
- function keyDownHandler(keyEvent: KeyboardEvent): void {
- if (keyEvent.keyCode == 32 || keyEvent.keyCode == 39) { //fires gun
- shootBullet();
- } else if (keyEvent.keyCode == 38 && player.y > 50) {
- player.y -= playerMoveSpeed; //moves player down
- } else if (keyEvent.keyCode == 40 && player.y < stage.stageHeight - 50) {
- player.y += playerMoveSpeed; //moves player up
- }
- }
Here's my touch code, which it seems to work, but I need it to match my keydownhandler
- function onTouchBegin (e:TouchEvent):void{
- player.y = e.stageY;
- trace(e.touchPointID);
- }
- function onTouchMove (e:TouchEvent):void{
- player.y = e.stageY;
- }
- function onTouchFinish (e:TouchEvent):void{
- player.y = e.stageY;
- }
So the problem here is:
a) playerMoveSpeed = 15, so keyboard players can only move at a limited speed however touch users can move with no limits
b) keydownhandler, prevents the player going off the screen while I dont think the touch code does
c) I cant seem to figure out a way to make touch users shoot, by tapping?
Thanks in advance for your help, looking forward to your reply.