PDA

View Full Version : help in making the character stop moving


Dreamias
09-13-2009, 10:15 PM
So I decided to try to make a character walk right left and jump up. Because I figure that's the basics of a game usually.

So I sought out many tutorials and learned as much as I could from them to try to understand the actionscript better. I understand most of it just not some of it.

I followed the instructions of many tutorials but none of them allowed me to make my character walk when the button is held down and stand still when you're not pressing the button.

This is the code I'm using.
Course I modified it some what.

onClipEvent (load) {
this.stop();
speed = 6;
jumpheight = 18;
fallspeed = 2;
gravity = 10;
scale = _xscale;
}
onClipEvent (enterFrame) {
if (_root.ground.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (air) {
_y += gravity;
}
if (air && gravity>0) {
this.gotoAndStop(3);
}
if (air && gravity<0) {
this.gotoAndStop(3);
}
if (Key.isDown(Key.RIGHT)) {
_root.ground._x -= speed;
_root.tra._x -= speed;
_xscale = scale;
}
if (Key.isDown(Key.LEFT)) {
_root.ground._x += speed;
_root.tra._x += speed;
_xscale = -scale;
}
if (!air && Key.isDown(Key.RIGHT) || !air && Key.isDown(Key.LEFT)) {
this.gotoAndStop(2);
}
if (!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) & !air) {
this.gotoAndStop(1);
}
if (Key.isDown(Key.SPACE) && !air) {
_y -= 5;
gravity = -jumpheight;
}
if (gravity<10) {
gravity += fallspeed;
}
if (_root.ground.hitTest(_x, _y-5, true)) {
_y -= 5;
}
if (_root.tra.hitTest(_x, _y, true)) {
_y -= 5;
gravity = -23;
}
}

I'd give you the actual game but I'm not too sure how.
Also I have movieclips with the jump and walking. It probably would be easier if I could show you the game, oh well.

Thank you for your time,
I appreciate it.

Powersclan
09-14-2009, 12:41 AM
What happens when you press the button and what happens when you dont?

Dreamias
09-14-2009, 03:05 AM
What happens when you press the button and what happens when you dont?

Well when I hold down the right arrow key it moves right, when I hold the left arrow key it goes left. But my problem is when I'm not pressing the keys the movie clip doesn't stop, it just keeps the walking animation going.

Powersclan
09-14-2009, 03:28 AM
ahhhh Notice the gotoAndStop?
(!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) & !air) {
this.gotoAndStop(1); <--------right there stop Gessing there theres another moiveclip inside of it? and when you do nothing does it have the same problem? and is this action script 3?

Dreamias
09-14-2009, 03:49 AM
ahhhh Notice the gotoAndStop?
(!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) & !air) {
this.gotoAndStop(1); <--------right there stop Gessing there theres another moiveclip inside of it? and when you do nothing does it have the same problem? and is this action script 3?

Yeah. It's like the clips don't do anything.
It's action script 2.

How can I put the game in the forum?
I've seen others do that and I think It'll help enormously.

and thanks.