Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a game on flash professional using AS2 (actionscript 2). I am now trying to release it for android. when playing the AS2 version, you use the arrow keys (Left, Right, Up and Down). There aren't arrow keys on android so i put onscreen arrow keys.

Left key (instance- left)

Right key (instance- right)

Up key (instance- up)

Down key (instance- down)

This is my original code

C#
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 7;
var maxJump:Number = -12;
var touchingGround:Boolean = false;
scale = _xscale;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
_x += speed;
this.gotoAndPlay(2);
}
if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
_x -= speed;
this.gotoAndPlay(2);
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
this.gotoAndPlay(3);
}
if (Key.isDown(Key.DOWN)){
this.gotoAndPlay(4);
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
}

onClipEvent (keyUp) {
this.gotoAndStop(1);
}



It would be much appreciated if you could change the code to suit the on screen buttons (instances provided above)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900