I’m making a simple game where the player uses ASDW to move a guy around the screen. The jumping works like i want it to. My left and right movement used to work, but now they don’t. Originally I had a layer for my actor and an instance of him on the screen. (My actor is a 5 frame loop of someone running; the first frame also contains variables like run speed, and jump velocity.) I now create my character my making a new movie clip adding an instance of my char to that movie clip then adding the movie clip to the stage.
The character sprites I’m using are from Mario games.
var mario:Mario = new Mario();
var mario_mc:MovieClip = new MovieClip;
mario_mc.addChild(mario);
stage.addChild(mario_mc);
mario_mc.x = 275;
mario_mc.y = 200;
The problem I’m encountering is when i try to move my movieClip left or right it warps to the left most edge of the screen. I did trace testing and i know it is setting the mario_mc.x to 0.
I use booleans to manage my X movement. On key press the boolean turns true on release it turns false. The frame is looped and when i enter the frame i update the X and Y positions of the movie clip.
if (mario_mc.left) {
mario_mc.play();
if (mario_mc.x>leftBound) {
mario_mc.x-=mario_mc.runSpeed;
} else {
mario_mc.x+=mario_mc.runSpeed * 2;
}
}
if (mario_mc.right) {
mario_mc.play();
if (mario_mc.x<rightBound) {
mario_mc.x+=mario_mc.runSpeed;
} else {
mario_mc.x-=mario_mc.runSpeed * 2;
}
}
I don’t think the problem is with the movement code but with the way i created my character. Any help/advice would be greatly appreciated.