View Full Version : Platform gaming help
Lord Maerk
May 4th, 2006, 09:40 AM
I followed Nathan's tutorial on Platform Gaming, but mine is having an error. When my character jumps, if I push left or right keys in mid air, he will start running. I am new at game programming and wondering what I could do to fix this. I used all of his code correctly (as in copy and paste) If anyone could give me a hand, it would be appreciated.
Nich
May 4th, 2006, 05:08 PM
You should have a variable called "inair" or something similar. In your movement code (something like "if(Key.isDown(Key.whatever)"), put the "gotoandPlay(blah)" in an if statement.
if(!inair)
{
gotoAndPlay("walk")
}
... if you post your code I can make something that's more specific.
Lord Maerk
May 5th, 2006, 09:38 AM
onClipEvent (load) { jumping = true; speed = 0; maxmove = 15; jump = 0; } onClipEvent (enterFrame) { if (_root.dead) { this.gotoAndStop("dead"); } else { speed *= .85; if (dir == "right") { if (speed>0) { dir = "right"; } else if (speed<0) { dir = "left"; } if (dir == "right"){ this._x += speed; _root._x -= speed; } if (dir == "left") { this._x += speed; _root._x -= speed; } if (Key.isDown(Key.LEFT)) { if (speed>-maxmove) { speed--; } this.gotoAndStop("run"); this._xscale = -100; } else if (Key.isDown(Key.RIGHT)) { if (speed<maxmove) { speed++; } this._xscale = 100; this.gotoAndStop("run"); } else if (speed<1 && speed>-1) { speed = 0; this.gotoAndStop("idle"); } if (Key.isDown(Key.UP) && !jumping) { jumping = true; } if (jumping) { this.gotoAndStop("jump"); this._y -= jump; jump -= .5; if (jump<0) { falling = true; } if (jump<-15) { jump = -15; } } if (_root.ground.hitTest(this._x, this._y, true) && falling) { jump = 12; jumping = false; falling = false; } } } Here it is. Just to reiterate, when I press up on the keypad, while in air I can press left or right and he will go to the run image and start moving in the respected direction. This is the direct code from Nathans tutorial but his MC in his game example doesn't do this.
Joppe
May 5th, 2006, 10:09 AM
^If you want help i suggest you format that code .
Lord Maerk
May 11th, 2006, 10:27 AM
Sorry about that. I ended up figuring it out though. My next problem is making "ground". I have mc called ground, and my main character has this ac on him:
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
jump = 12;
jumping = false;
falling = false;
Now he will be able to stop on 1 ground, so then I put another instance of ground on the stage and he will fall through every time.
Joppe
May 11th, 2006, 12:33 PM
Would you mind posting an fla?
nathan99
May 12th, 2006, 09:58 AM
Yeah, post a FLA, much more luck;)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.