View Full Version : stop moving the right way...
Bunzing
06-24-2002, 10:48 AM
i have this on an instance called vegaloop:
onClipEvent (load) {
speed = 17;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_root.vegaloop.gotoAndStop(5);
_x -= speed;
} else if (Key.isDown(Key.RIGHT)) {
_root.vegaloop.gotoAndStop(10);
_x += speed;
}
}
pressing the left button goes to an instance of a figure walking to the left. when i release the left button, it stops moving to the left, but it keeps walking....the same goes for the right button now, when you stop pressing the right-button i want to show the instance that faces the right direction (Which has no movement), and when you stop pressing the left-button, i want to show the instance facing the left direction (which hasn't movement either)
am i making sense here?
:confused:
I have tried a lot of things, with either ELSE or ELSE IF, but it doesn't do the trick.....
Can anybody tell me how to do this?
Billy T
06-24-2002, 11:17 AM
put the still image facing left in frame 6 and the still image facing right in frame 11 and add something like this
onClipEvent(keyUp){
_root.vegaloop.gotoAndStop(_currentframe+1);
}
cheers
Hi,
When you try and build something like this make it as uncomplicated as you can. Build sequencially, and add functionality as you go along. That way you know what's going wrong, and you'll probably guess why. Also, don't get too complicated unless necessary, and label frames rather than refering to there number as the code is easier to read as well as allowing you to rearrange your timelines if necessary.
Create a new MC as a control clip. On the SECOND frame put;
gotoAndPlay(1);
which causes the control clip to loop continuously (and therefore check for keyboard activity continuously). Everything else goes on the FIRST frame of the control MC.
Logical code for the walking might be something like:
if (Key.isDown(Key.LEFT)) {
_root.vegaloop.gotoAndStop("walkingLeft");
}
if (Key.isDown(Key.RIGHT)) {
_root.vegaloop.gotoAndStop("walkingRight");
}
else{
_root.vegaloop.gotoAndStop(_root.facingDirection);
}
Then you add a variable to tell which way the clip should be facing. Something like;
_root.facingDirection="left";
Once you've done that, add the movement of the MC, remembering that you probably want to limit it;
vegaloopSpeed=10;
if(_root.vegaloop._x <= 10){
_root.vegaloop._x = _root.vegaloop._x;
}
else{
_root.vegaloop._x = _root.vegaloop._x - vegaloopSpeed;
}
Then all you need to do is put it together:
______________________________________________
//SET SPEED
vegaloopSpeed=10;
/*
FIND OUT IF A KEY IS DOWN
IF IT IS GO TO THE RIGHT WALKING ANIMATION, SET THE VARIABLE 'facingDirection' TO THE RIGHT WAY, IF THE CLIP'S INSIDE THE STAGE AREA MOVE IT IN THE RIGHT DIRECTION.
*/
if (Key.isDown(Key.LEFT)) {
_root.vegaloop.gotoAndStop("walkingLeft");
_root.facingDirection="left";
if(_root.vegaloop._x <= 10){
_root.vegaloop._x = _root.vegaloop._x;
}
else{
_root.vegaloop._x = _root.vegaloop._x - vegaloopSpeed;
}
}
if (Key.isDown(Key.RIGHT)) {
_root.vegaloop.gotoAndStop("walkingRight");
_root.facingDirection="right";
if(_root.vegaloop._x >=290){
_root.vegaloop._x = _root.vegaloop._x;
}
else{
_root.vegaloop._x = _root.vegaloop._x + vegaloopSpeed;
}
}
/*
IF A KEY ISN'T DOWN, SEND THE CLIP TO THE FRAME LABEL, EITHER 'left' OR 'right' DEPENDING ON WHICH KEY WAS PRESSED LAST.
*/
else{
_root.vegaloop.gotoAndStop(_root.facingDirection);
}
__________________________________________________
cheers.
Bunzing
06-24-2002, 11:50 AM
Thanx! you've been a great help!:D :D
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.