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
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)