PDA

View Full Version : [AS2] Another character movement problems


Andy|Robot
02-27-2009, 01:11 AM
My problem is there is so much information on character movement that i can't find the piece of information i need.

Basically my background moves and the character jumps separating, but it has a pause when holding LEFT then jumping the LEFT movement in the background will stop and only start after the jump key has been released and pressed again or untill the left has been released and pressed again. I'ts most likely to do with all the stop(); 's i have.

The animation has 2 elements - a rotating background and a jumping/flipping character, this is all test work to implement into a game later on.

.FLA file: rotatecontrolcharacters1.fla (http://andy.gamescreator.googlepages.com/rotatecontrolcharactertest1.fla)

Character_mc code:
onClipEvent (load) {
jumping = false;
velocity = 10;
stop();
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
jumping = true;
}
if (jumping) {
this._y -= velocity/2;
velocity -= .3;
}
if (this._y > 104) {
jumping = false;
velocity = 10;
}
}
onClipEvent (keyDown) {
if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop("Right");
}
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("Left");
}
}
onClipEvent (keyUp) {
if (!Key.isDown(Key.LEFT || Key.RIGHT)) {
this.gotoAndStop("Front");
}
}

Background_mc code:

onClipEvent (enterFrame) {
this.stop();
}

onClipEvent (keyDown) {
if (Key.isDown(Key.RIGHT)) {
if (this._currentframe > 299){
this.gotoAndStop(1);
this._currentframe = 1
}else{
this.gotoAndStop(this._currentframe +1 );
}
}
if (Key.isDown(Key.LEFT)) {
if (this._currentframe < 2){
this.gotoAndStop(300);
this._currentframe = 300
}else{
this.gotoAndStop(this._currentframe -1);
}
}
}
onClipEvent (keyUp) {
if (!Key.isDown(Key.LEFT || Key.RIGHT)) {
this.stop();
}
}


Help is much appreciated :)
Andy

kkbbcute
02-27-2009, 06:55 AM
it has a pause when holding LEFT then jumping the LEFT movement in the background will stop and only start after the jump key has been released and pressed again or untill the left has been released and pressed again.

Sorry but I didn't really catch that, could you rephrase it?

Andy|Robot
02-27-2009, 11:15 AM
//*erm well its probably best to download it but basically when ever i jump it stops the left movement even though i am holding down the left key (the same with pressing the right key)*//

Never mind i just fixed it, i had to move the code into onClipEvent(enterframe) instead off onClipEvent(keyDown)