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.
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.