there have been a few people asking how i make my jumping engines, so i forced myself to write this tutorial.it is also my first.
at the end of the tutorial, you will get something like this: My Jumping Engine
note that the .swf is not a complete game, i just made it for tutorial purposes.
s to jump,
left and right to move.
the red things are enemies (note: i won't be teaching how to make enemies just yet)
if you don't like how the engine looks, or think that i am in no position to make a tutorial because i am a noob, or for whatever reason, then don't bother even reading this, you hear?
first of all, let me explain that i am not going to put exact code, just pseudocode, so you just can't copy and paste, and that i will put code of different use in different onClipEvents to make it easier to understand, so experts, stop saying stuff like "Put that in one onClipEvent!", this is made for beginners, anyway.
so, your first step is to animate your character., fame 1 being the standing frame. add walking left and right animations, and a jumping animation.
then put stuff like this on the character MC named "player":
onClipEvent(enterframe){
if(Key.isDown(Key.RIGHT)&&this._currentfra
me==1){
gotoAndPlay(the frame where he faces right)
}
else if(Key.isDown(Key.LEFT)&this._currentframe
==1){
gotoAndPlay(the frame where he faces left)
}}
if you're wondering why there is a "&&this._currentframe==1", this is to make sure it doesn't stop at the frame you made it gotoAndPlay to.do this only if your walking animations are directly inside the player MC, not when you have "walking left" and "walking right" MCs inside the player MC. otherwise, leave that code out.
gravity:
declare these variables first:
onClipEvent(load){
_root.gracvity=10
_root.speed=10
}
kep in mind that the value of these variables is up to you, tweak the values if you see that they are unsuitable for your view of a game.
put this in your character MC:
onClipEvent(enterframe){
if(!(_root.bkg.walls.hittest(this._x, this._y, true)or_root.bkg.walls.hittest(this._x+(th
is._width/2-5), this._y, true)or_root.bkg.walls.hittest(this._x-(th
is._width/2-5), this._y, true))&&this._currentframe<=(the frame that shows the jumping animation))){
//this means if the character is in the air, or jumping
this._y+=_root.gravity
_root.gravity+=0.5
//this is to give the illusion of increasing fall speed, even though it is just tiny
}
else{
//this means if the character is on land
_root.gravity=10
//gravity reverts to its normal value
}}
jumping:
animate your character jumping, and on each frame where he is supposedly going vertically, add this code in the frame:
_root.player._y-=(_root.gravity+10)
this is so that you know exactly what value your character can jump.
for example, if there are 6 jumping frames, the first two can have a net height increase of 15, the next two 10, then the last two 5, to give the illusion of it slowing down.this is the part with which most ASers disagree with.then again, i said it's my jumping engine, so that means i never ripped from anyone.it was my idea entirely.
then put this code in your MC:
if(Key.isDown(Key.UP)&&this._currentframe<
=(the frame that shows the jumping animation)){
gotoAndPlay(the frame that has the jumping animation)}
REMINDER: i can almost feel you saying to your computer screen "this code is st00peed!what kinda noob made this?!" well, as i said, this is for a jumping engine that will look like the .swf in the link above.i'm just telling you how it is made.if you don't like it so far, PLEASE STOP READING
walking:
put this in your character MC:
if(Key.isDown(Key.RIGHT)&&!_root.bkg.walls
.hittest(this._x+(this._width/2-5), this._y-(this._height/2-5), true)&&this._x<(insert width of movie here, subtract 100 from it. this is so, the character can only walk a certain distance from the center)){
this._x+=_root.speed
else if(Key.isDown(Key.RIGHT)&&!_root.bkg.walls
.hittest(this._x+(this._width/2-5), this._y-(this._height/2-5), true)&&this._x>=(insert width of movie here, subtract 100 from it.)){
_root.bkg._x-=_root.speed
}
do this for when pressing left too, i guess you can do that on your own.
the effect is like the one in metal slug, where the background moves only if the character is near the edge of the screen.
this works better in 24 fps, by the way.
make an MC "wall" inside an MC "bkg", then in the "bkg" MC, on a layer above the "wall" MC, draw the level in detail. then make the alpha of the "walls" MC be 0 to make it invisible.
and there you have it, that is the engine i work with.cheerio!
REMINDER: this tutorial is to show you how i do it, this does not necessarily (sp?) mean it is the only and the best way to do it. for more fun and learning, make your own engine, i don't want people flooding the portal with half-baked platformers that look all alike.