00:00
00:00

AS:Platformer

8,823 Views | 22 Replies
New Topic Respond to this Topic

AS:Platformer 2005-09-03 20:16:30


Platform Game Preview(my upcoming game)

I know...Atomic Sponge made one...my turn :D

Ok,first I'll start with anything before the coding.

Make your character.Make him/her/it into a MovieClip.Make sure the Center of your MovieClip is in between your characters legs.Use Onion Skinning to do the same for the next frames in the MovieClip.On your first frame,add a stop action.Make sure your character is there .Add another frame.Add a MovieClip of your character running,along with a stop action.Now add one last frame.This frame is your character in a jumping position.It doesn't have to be a MovieClip or anything,but do what you want.

Next,you need to create Platforms.Either way,the Platforms need to be a MovieClip.You can animate them if you want.It doesn't matter how many Platforms you have,they all belong in the same MovieClip per lvl of your game.Outside of your Platforms on the selected scene,add the instance name of "Platforms" to your Platforms so the hitTest on your character works.Of course there are no quotes.Also remember that your Platforms eventually should be covered up by a real Platform part,as in a Mario walking thingy or whatever.I suggest always putting your Platforms that your character is on to be on the very bottom layer behind the background,platform pictures,and whatever so they aren't seen.

Now I'll start off with the coding variables and such.

onClipEvent (load) {
gravity = 10;
walkSpeed = 6;
maxJump = 4;
scale = _xscale;
}

The (load) onClipEvent is always needed for setting variables.Now then...

Gravity...this will set how much Gravity is in your character.10 will have to be the Gravity for the code to work right.

walkSpeed...this tells how fast or slow your character will walk.6 is an average walk rate.

maxJump...this is part of the jumping script area in the full code.Set it to whatever.

scale and _xscale...this will make your character change direction depending on which key you use.How does this variable work?It tells that the scale variable you are using is _xscale rather than _yscale.I'm actually not sure whether or not it's needed in the variables...ok then,next part.

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
_x -= walkSpeed;
this.gotoAndStop(2);
}
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
_x += walkSpeed;
this.gotoAndStop(2);
}

The (enterFrame) onClipEvent is always used for hitTest or arrow movment.There are also other uses that we won't need in this tutorial.

First of all,the if(Key.isDown(Key.set)) will be the "if" for pressing a Key down.If your smart enough,you'll have figured out that when there's an "if",there's a "then".So you see all that's past the second { in that code?That's the "then" part._xscale = -scale will make your character turn to the Left while the Key is down._xscale = +scale is the same thing,just for the Right._x -= walkSpeed is setting what direction the character will go with the speed.You notice that "-" on the walk part is for Left.Everything thing above is the same for Right,except opposite.The gotoAndStop(2); code makes your character go to the second frame,which if you remember,is the frame for running/walking.It's the same for both since both codes lead to the 2nd frame.On to the next part of this code...

if (air == true) {
_y += gravity;
}
}
onClipEvent (enterFrame) {
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}

This area is for the gravity.The first "if" part is so the gravity will start when your character is in the air._y += gravity; will make your move down automatically,almost like the Key.isDown code,except this time,there is no Key actions.The next part is for landing on your platforms.As you can see,a hitTest is started.You also see the word "Platforms" in there.There really is a use for that instance .The "then" part of this hitTest makes it so air = false;,which means that the character should stop falling.The "else" is kinda like an "if",but shorter.It's a continuing "if" for incase the character is in the air,which makes the possibility of even being in the air possible!(Confusing,eh? )Ok,we'll stop that now.As a conclusion to Platforms,you need to keep this in your head....make sure every Platform is located in 1(just ONE!)single MovieClip per lvl.For example,create your rectangle Platforms with the Rec. Tool,then convert them all into on MC.This goes for every lvl(platformslvl1.1,platformslvl1.2,etc etc)Let's continue...

if (Key.isDown(Key.UP) && jump == true) {
_y -= jumpSpeed;
gotoAndStop(3);
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (Key.isDown(Key.UP)) {
jumpcount += 1;
this.gotoAndStop(3);
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
}

I bet you were wondering about the jump...ok,we have another Key.isDown code.Except this time it's for going "Up".You notice the "&&" part of this code.This is also like a continue of the "if",except for it's for 2 "if"s at once...and you should know that _y - =jumpSpeed will make your character jump into the air at that variable rate you set earlier.Then here is a toughy...this is almost like a new variable setter,but it's with an "if" function.This is for when your character is on the Platform.It makes it so you may jump(jump = true),jumpcount = 0;(no more jumping),and jumpSpeed = 22(also no more jumping).Then the next part.Jumpcount += 1.This raises 0 to 1,which is part of the jumping and falling.Kinda makes it realistic...not just jump and suddenly fall.Jump,slow down,then fall...and finally,a part for actually jumping.this.gotoAndStop(3); will make your character go to jumping position.Sorry about some bugs in the jumping part.The rest is all part of the slowdown process I mentioned a few seconds ago.It will set the jumpSpeed down 2 so falling is in act.On we go...

onClipEvent (keyUp) {
this.gotoAndStop(1);
walkSpeed = 6;
}

The (keyUp) onClipEvent...Simple eh.This makes it so when any key pops back up on your keyboard,the character will go back to frame 1,which is the standing frame.(This is one part of my jumping bug).walkSpeed = 6; is just a part for if you add something to make your character faster during walk...whatever.Now I will add a few extra things for making a platform game.

<<<Read Next Post>>>


wat

Response to AS:Platformer 2005-09-03 20:19:43


Part 2

onClipEvent (enterFrame) {
if (this._x>=545) {
this._x = 540
}
if (this._x<=10) {
this._x = 15;
}
}

More confusing for you?This code is for Action Scripted walls.I'm just going to assume you have a 550x400px stage.If the 550px is any bigger,just change the

if (this._x>=545) {
this._x = 540
}

numbers to the size.The first number is the width number,and the second number is 5 px less than the first.This code makes it so if your character is at the 10 or 550px points,it will be forced back 5px with the code.You want a couple numbers less than your frame size at the first part on the 545 part or whatever so you don't manage to fall off the edge or something.You can also use one of these codes for going the the next lvl of your game.Next...

For the last part,you need something for attacks...so I'm assuming you'll use letters on the Keyboard for that,right? .I just figured out that the number "65" in Flash codes stood for the letter "A".So I used common sense and started naming the numbers for other letters."65"=a,"66"=b,etc etc.So I'll list each number and it's matching letter for in Flash.

65=A
66=B
67=C
68=D
69=E
70=F
71=G
72=H
73=I
74=J
75=K
76=L
77=M
78=N
79=O
80=P
81=Q
82=R
83=S
84=T
85=U
86=V
87=W
88=X
89=Y
90=Z

Long huh?Well there are 26 letters in the Alphabet...back to the main topic.Now,the Key.isDown for Letters is different.I'm gonna refer letters to "Keycodes" now since that's the Flash name use.Below is an example of a Keycode Key.isDown...

onClipEvent (enterFrame) {
if (Key.isDown(65)) {
this.gotoAndStop(4);
walkSpeed = 0;
}
}

Do you see the difference?You should...Instead of Key.65,I've just used the Keycode "65".If you have Key.65,you'll get a Syntax Error in your Action Script menu.Simple?Also,where it says this.gotoAndStop(4);,the character(your code is in the character,right?)will go to frame 4,which is where your attack MC should be at.Also,I've got walkspeed set to 0 since I haven't figured out a running while attacking code yet(I can figure out a Platform Code,but not a simple run/attack code? )You see this is part of that (keyUp) onClipEvent I mentioned earlier,where the walkspeed is set back to 6.There,now you have a simple attack method.One thing left...

Now to make everything easier on you,I'm going to post the entire Platform Code for easier copying...just remember to start making your own codes...

onClipEvent (load) {
gravity = 10;
walkSpeed = 6;
maxJump = 4;
scale = _xscale;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
_x -= walkSpeed;
this.gotoAndStop(2);
}
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
_x += walkSpeed;
this.gotoAndStop(2);
}
if (air == true) {
_y += gravity;
state = 3;
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (Key.isDown(Key.UP) && jump == true) {
_y -= jumpSpeed;
gotoAndStop(3);
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (Key.isDown(Key.UP)) {
jumpcount += 1;
this.gotoAndStop(3);
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
walkSpeed = 6;
}
onClipEvent (enterFrame) {
if (this._x>=545) {
this._x = 540
}
if (this._x<=10) {
this._x = 15;
}
}

(Please note that the code above is every code I posted(except for attacking)put together in a couple onClipEvents for some script saving.)

*Stretches Fingers*There,I'm pretty sure that's all I have to say on Platform Games.Happy Flash making.


wat

Response to AS:Platformer 2005-09-03 20:21:26


Well this seems to be a dumbed down version of my one and atomic sponges and im pretty sure quite a few others
Nice though keep it up


- Matt, Rustyarcade.com

Response to AS:Platformer 2005-09-03 20:24:07


Sadly this code only works for Flash MX :(

As soon as I get a full Flash 7 or 8 or something,I have to upgrade the jumping system so you don't fly with a jetpack...the good thing is that I can make a Platformer with the V-Cam :D

Wonder why both long posts came so fast?

Answer=I made this tutorial on ngcollabs.com and copied it here.


wat

Response to AS:Platformer 2005-09-03 21:09:34


At 9/3/05 08:24 PM, Thomas2005 wrote: Sadly this code only works for Flash MX :(

As soon as I get a full Flash 7 or 8 or something,I have to upgrade the jumping system so you don't fly with a jetpack...the good thing is that I can make a Platformer with the V-Cam :D

Wonder why both long posts came so fast?

Answer=I made this tutorial on ngcollabs.com and copied it here.

Yeah I still havnt bothered learning the V-cam maybe I should start now


- Matt, Rustyarcade.com

Response to AS:Platformer 2005-09-10 18:22:59


Ok,I came up with a code for Flash MX Pro(quite a while ago),so here it is.It's basically the same thing above,just more if's to make it work.

onClipEvent (load) {
gravity = 10;
maxJump = 6;
scale = _xscale;
walkSpeed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
_x -= walkSpeed;
this.gotoAndStop(2);
}
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
_x += walkSpeed;
this.gotoAndStop(2);
}
}
onClipEvent (enterFrame) {
if (air == true) {
this._y += gravity;
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (air == false) {
jump = false;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (Key.isDown(Key.UP)) {
jumpcount += 1;
}
if (Key.isDown(Key.UP) && jump == true) {
_y -= jumpSpeed;
this.gotoAndStop(3);
}
if (jumpcount>maxJump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
if (this._x>550) {
this._x=550
}
if (this._x<10) {
this._x = 10;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
}

If you read everything above,you'll notice they are similar,but with some different coding to make the gravity and jumping work.Flash MX version makes it work better...


wat

Response to AS:Platformer 2005-09-20 20:26:48


I tried making a game with a stickman using the code you gave but his legs seem to go through the ground. do you know why this is happening?

Response to AS:Platformer 2005-09-20 20:29:28


happens to me too. i named its instance ground, but he goes through, but not all the way

Response to AS:Platformer 2005-09-20 20:50:45


Set the "hot-spot" ( crosshair ) to his feet.


These new signatures can suck on mah balls. My lolis don't fit in. Lol wut what are you guys still doing on NG, move on.

BBS Signature

Response to AS:Platformer 2005-09-20 21:01:02


The more codes we have, the better. It's not good to limit it to one person. Also, this way I won't get so many instant messages from idiots who can't figure out what anything means. Thanks!


BBS Signature

Response to AS:Platformer 2005-10-10 12:56:09


I put 2 extra frames for the attacking part and it only plays the first frame of the attack and not the whole thing. Anybody know why?


BBS Signature

Response to AS:Platformer 2005-10-10 12:58:18


At 10/10/05 12:56 PM, MegaManFan wrote: I put 2 extra frames for the attacking part and it only plays the first frame of the attack and not the whole thing. Anybody know why?

sorry. Forgot to say something also. I can't create multiple platforms.


BBS Signature

Response to AS:Platformer 2005-10-10 12:59:54


How many times will I have to say it again?! More than half of it is actually the jumping engine I made for you ages ago, and it doesn't work that well...


BBS Signature

Response to AS:Platformer 2005-10-10 13:08:09


onClipEvent (load) {
gravity = 10;
walkSpeed = 6;
maxJump = 4;
scale = _xscale;

Use correct syntax!

}

So far, it's exactly the same, same variables, same numbers.

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
_x -= walkSpeed;
this.gotoAndStop(2);
}
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
_x += walkSpeed;
this.gotoAndStop(2);
}

Still same...

if (air == true) {
_y += gravity;
state = 3;
}

Same...

if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}

OMG! Same thing as in my code!

if (Key.isDown(Key.UP) && jump == true) {
_y -= jumpSpeed;
gotoAndStop(3);
}

You changed "jump" to "jump == true"

if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}

Lol, same variables, same numbers

if (Key.isDown(Key.UP)) {
jumpcount += 1;
this.gotoAndStop(3);
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
walkSpeed = 6;
}

Almost same, except you deleted the keyCode check...

onClipEvent (enterFrame) {
if (this._x>=545) {
this._x = 540
}
if (this._x<=10) {
this._x = 15;
}
}

Okay, this part wasn't in my code.

Dude, you basically took my old code and added:
onClipEvent (enterFrame) {
if (this._x>=545) {
this._x = 540
}
if (this._x<=10) {
this._x = 15;
}
}


BBS Signature

Response to AS:Platformer 2005-10-16 23:23:20


At 10/10/05 12:59 PM, -Toast- wrote: How many times will I have to say it again?! More than half of it is actually the jumping engine I made for you ages ago, and it doesn't work that well...

I swear...I AM GOING TO KILL YOU.

I never used your jumping code once.I don't care about your jumping code.I forgot about your code when I made this platform code.I didn't have the game file with that code on the CPU I made this code with.Just STFU and lay off.


wat

Response to AS:Platformer 2006-05-14 15:51:00


im a newb.... i chang the code so that when you hit up he dose the full jump on his own.. and also when you move in the air it dose not show the walking fram..

onClipEvent (load) {
gravity = 10;
maxJump = 6;
scale = _xscale;
walkSpeed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) && air == false) {
_xscale = -scale;
_x -= walkSpeed;
this.gotoAndStop(2);
}
if (Key.isDown(Key.RIGHT)&& air == false) {
_xscale = +scale;
_x += walkSpeed;
this.gotoAndStop(2);
}
if (Key.isDown(Key.LEFT) && air == true) {
_xscale = -scale;
_x -= walkSpeed;
this.gotoAndStop(3);
}
if (Key.isDown(Key.RIGHT)&& air == true) {
_xscale = +scale;
_x += walkSpeed;
this.gotoAndStop(3);
}
}
onClipEvent (enterFrame) {
if (air == true) {
this._y += gravity;
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;

}
if (air == false) {
jump = false;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (air == true) {
jumpcount += 1;
}
if (Key.isDown(Key.UP) && jump == true && air == false) {
_y -= jumpSpeed;
}
if(jump == true && air == true){
_y -= jumpSpeed;

}
if (jumpcount>maxJump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
if (this._x>550) {
this._x=550
}
if (this._x<10) {
this._x = 10;
}
}
onClipEvent (keyUp) {
if(air == false){
this.gotoAndStop(1);
}
}

BTW how do you add more then one platform??????????

Response to AS:Platformer 2006-05-14 15:58:04


At 9/3/05 09:09 PM, Ninja-chicken wrote: Yeah I still havnt bothered learning the V-cam maybe I should start now

Oh my God, this thread must be really old!


BBS Signature

Response to AS:Platformer 2006-05-14 16:28:16


Yes, I am clearly an idiot. Can anyone just give me the code for the walls straight. I don't want it explained. PLEASE!!!

Response to AS:Platformer 2007-09-08 14:13:06


At 9/20/05 08:29 PM, iggy101 wrote: happens to me too. i named its instance ground, but he goes through, but not all the way

happens to me too. exept i got all the way through the ground


.watch my latest news

*its all in the brain...where the brain is ..well thats ur problem.

BBS Signature

Response to AS:Platformer 2007-11-26 16:00:23


I use that music in one of my movies!


.

Response to AS:Platformer 2008-07-05 22:40:13


I got a question Oo What does "state = 3" do exactly? I don't se another referrer.... is that some type of property or is it a special variable? Slightly cunfused because there's no flv to playback?

Plus, you should stop use "air" as a variable becuase since Adobe Air came out the air variable is used to transfer stuff between air and flash code.

Response to AS:Platformer 2008-07-06 06:35:38


We need less clueless programmers and more skilled programmers.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Response to AS:Platformer 2008-07-06 09:54:12


At 7/6/08 06:35 AM, henke37 wrote: We need less clueless programmers and more skilled programmers.

So start working XD