Scrolling and Movement(NOT WORKING)
I am trying to make a game that has scrolling background and my character is not moving when I tried to make scrolling background. But Jumping is working. Yeah.
I first made the gravity with a function that is own a layer. Look at file. I made a movie clip called ground. And Here is the Action Script. It works.
PHP Code:
// Set our variables
jumpAmount = 15;
gravity = 1;
onGround = true;
_root.onEnterFrame = function() {
if (Key.isDown(key.SPACE)) {
onGround = false;
}
if (!onGround) {
player._y -= jumpAmount;
jumpAmount -= gravity;
}
if (player.hitTest(ground)) {
onGround = true;
}
if (onGround) {
jumpAmount = 15;
}
};
Then when I tried to make the scrolling background. This is what I did. I first made a movie clip called bg(instances name the same). bg servers as ground. Then I went in to the movie clip and made a two walls called lhit and rhit. This is were my character will stop when he is walking.
On my character I put this action script for the scrolling and movement and character development(alt=punch and apple key= punch).
PHP Code:
onClipEvent (load) {
speed = 5;
grav = 0;
}
onClipEvent (enterFrame) {
// gravity
if (!_root.ground.hitTest(_x, _y+1, true)) {
grav += 1;
_y += grav;
} else {
grav = 0;
}
while (_root.ground.hitTest(_x, _y, true)) {
_y -= 1;
}
// movement
if (Key.isDown(key.RIGHT) && player._x<400) {
player._x += xmov;
} else if (Key.isDown(key.RIGHT) && player._x>399) {
bg._x -= xmov;
player._x += 0;
}
if (Key.isDown(key.LEFT) && player._x>150) {
player._x -= xmov;
} else if (Key.isDown(key.LEFT) && player._x<151) {
bg._x += xmov;
player._x += 0;
}
if (player.hitTest(bg.lhit)) {
player._x += xmov;
}
if (player.hitTest(bg.rhit)) {
player._x -= xmov;
} else if (Key.isDown(Key.ALT)) {
gotoAndStop(3);
punch.play();
} else if (Key.isDown(Key.CONTROL)) {
gotoAndStop(4);
punch2.play();
}
}
Also, when I punch he falls to the center of the ground. Is that because the resigtartion mark.
I have included my FLA file. It is Flash MX form.