00:00
00:00
Newgrounds Background Image Theme

MoxKatt just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS:Ground Movement

11,804 Views | 36 Replies
New Topic Respond to this Topic

AS:Ground Movement 2005-10-26 19:55:10


@5:/\/\@1|\|!!!!!!!11111
__________
This tutorial will teach you the basics to a game like Dad 'n Me...the movement style.

See what I'm talking about

Before you do anything,make a new movieclip.Make 2 frames.In the first frame,add a picture of your character standing.In the second frame,add a movieclip of your character running/walking.Also,add stop(); actions to each frame.Now keep reading.

Please don't be stupid.Add the code to the character MC :)

Start off by adding the variables.

onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}

We'll need to separate speed settings,one for the _x movement and one for the _y movement.The speeds need to be different,to give the game a somewhat realism effect thingy.Also,we'll use _xscale to change which way the character faces on each key press.

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= speed2;
this.gotoAndStop(2);
}

'if':Here is the first ClipEvent.Using te 'if' function,we can create a Key.isDown function,so you can make the effects.When there is an 'if',there is a 'then'.Now,the first part of the script will be Key.UP.This doesn't really have to be UP,but it is right now.
'then':Now,your then will be movement and making your character walk.If you remember,the movieclip has 2 frames,standing and walking.You will be directed to frame 2 in the movie test when you press the buttons.Also,_y -= speed2; will make your character move upwards,and as you see,with him still facing one direction:left or right.The next parts of the script are exactly the same,just changed for different directions.

if (Key.isDown(Key.DOWN)) {
this._y += speed2;
this.gotoAndStop(2);
}

Same,just moves your character down with a 'plus'(+) sign.

if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}

You notice 2 things in this part of the script._y has changed to _x,and a new 'then' code has been added,the _xscale code so your character will turn.Please make sure your character starts off facing the right way :)

if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop(2);
_xscale = +scale;
}
}
Same as above,just the 'minus'(-) sign has been changed to a 'plus'.

Now,to end this script,we need to use a new script to change the frame back to frame 1 and stop the walk/run animation.

onClipEvent (keyUp) {
this.gotoAndStop(1);
}

Notice how 'enterFrame' changed to 'keyUp'?Yah.

Here is the full code...

onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
this._y -= speed2;
this.gotoAndStop(2);
}
if (Key.isDown(Key.DOWN)) {
this._y += speed2;
this.gotoAndStop(2);
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop(2);
_xscale = +scale;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
}

Change the speed to whatever to make the speeds faster or whatever.Also,if you want to make the movement work with the keys 'W','S','A',and 'D',then just use the keycode example below...

65=A=LEFT
68=D=RIGHT
83=S=DOWN
87=W=UP

Do not make the code Key.65 or whatever,just use the number...example.

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

The end :)


wat

Response to AS:Ground Movement 2005-10-26 19:58:01


thats a good basic tutorial :)

hmm maybe I should make my quasi-3d depth-field engine open source :P


I was never really here.

Response to AS:Ground Movement 2005-10-26 20:03:48


I'd like to see that

Response to AS:Ground Movement 2005-10-26 20:04:03


Oh cool I got complimented by a website affiliate :)


wat

Response to AS:Ground Movement 2005-10-31 12:39:57


You might also consider:

onClipEvent(enterFrame){
this.swapDepths(this._y+10);
}

On all your moving mc's

So your character can walk in front of and behind eachother depending on their _y value.

Heigher _y = heigher depth = in front of more stuff

I added a +10 just to boost it away from the 0 mark, going under 0 in depths results in loss of functionality such as removeMovieClip(), so its a good idea to keep them at depths >1, change the 10 according the the mc's height.

Response to AS:Ground Movement 2005-10-31 12:46:55


At 10/31/05 12:39 PM, T-H wrote: onClipEvent(enterFrame){
this.swapDepths(this._y+10);
}

That's a very good idea, I have to admit I would never think of it. It's just like _currentframe, a simple way to avoid big mess.


BBS Signature

Response to AS:Ground Movement 2005-10-31 12:59:43


Just a question: How can you know/trace an object's depth?
You can't do like, trace(this.swapDepths()), can you? =/


BBS Signature

Response to AS:Ground Movement 2005-10-31 13:00:33


Thankyou T-H. I was just about to ask that question.

How, and where, would it be replaced and stuff?


"Actually, the server timed out trying to remove all your posts..."

-TomFulp

Response to AS:Ground Movement 2005-10-31 13:06:23


At 10/31/05 12:59 PM, -Toast- wrote: Just a question: How can you know/trace an object's depth?
You can't do like, trace(this.swapDepths()), can you? =/

Nevermind, I have an idea:

onClipEvent(enterFrame){
this.swapDepths(this._y+10);
myVar = this._y+10;
}

Then you can trace myVar and it will give you the depth.


BBS Signature

Response to AS:Ground Movement 2005-10-31 13:07:55


At 10/31/05 12:59 PM, -Toast- wrote: trace(this.swapDepths())

trace(this.getDepth());


BBS Signature

Response to AS:Ground Movement 2005-10-31 13:08:55


At 10/31/05 01:06 PM, -Toast- wrote: Then you can trace myVar and it will give you the depth.

trace(instance.getDepth());

Dude, look here.


Sup, bitches :)

BBS Signature

Response to AS:Ground Movement 2005-10-31 13:13:09


At 10/31/05 01:08 PM, -liam- wrote:
At 10/31/05 01:06 PM, -Toast- wrote: Then you can trace myVar and it will give you the depth.
trace(instance.getDepth());

Bleh, didn't know it existed :)

Dude, look here.

Bleh, didn't know it existed :)

Thanks Liam!


BBS Signature

Response to AS:Ground Movement 2005-10-31 13:15:25


There is also a getInstanceAtDepth(number); (not sure if thats the exact syntax)

If you fancy targetting a mc at a certain depth to alter/remove it, never used that one before.

Response to AS:Ground Movement 2005-10-31 13:36:42


At 10/31/05 01:15 PM, T-H wrote: There is also a getInstanceAtDepth(number); (not sure if thats the exact syntax)

If you fancy targetting a mc at a certain depth to alter/remove it, never used that one before.

I have for one thing.. I made this:

function removeTarget(depth:Number):Void {
_root.removeMovieClip(_root.removeInstance
AtDepth(depth))
}

I made the MCs to be removed swap depths, then run that function just to see if it worked =)

it did.

Sup, bitches :)

BBS Signature

Response to AS:Ground Movement 2005-10-31 13:38:02


At 10/31/05 01:36 PM, -liam- wrote: _root.removeInstanceAtDepth

That was supposed to read "getInstanceAtDepth", har.. har.


Sup, bitches :)

BBS Signature

Response to AS:Ground Movement 2005-10-31 13:38:52


:D


BBS Signature

Response to AS:Ground Movement 2005-11-02 21:10:18


At 10/31/05 01:38 PM, -Toast- wrote:
D

When you go behind the first-left building,then go up to touch the one above it,you go behind it.


wat

Response to AS:Ground Movement 2006-07-24 16:33:18


hi, i really suck at AS and I was wondering if you could help me out by adding a 'jump' button but not changing the action script ....please?

Response to AS:Ground Movement 2006-07-25 07:29:20


pretty please?...

Response to AS:Ground Movement 2006-11-08 18:37:29


How do you make a wall?You know I want to know how to make a simple wall.Please help?


hello

Response to AS:Ground Movement 2007-01-19 17:36:52


At 11/8/06 06:37 PM, Tek-dude wrote: How do you make a wall?You know I want to know how to make a simple wall.Please help?

YES that would help A LOT, i'd be PERFECT for the game I'm making

; somebody do it PLZ

PLEASE
)

Response to AS:Ground Movement 2007-03-09 19:01:16


The only problem I see is you have the _xscale flip on key press so if the toon is facing right and you hit the right button he turns left.

if you have the scale for left and right set to variables and just call the varable rather than adding the scale to it it would work a little smoother but good over all.

I'll tinker with the code a bit and see what I can come up with.


Visit JackSmack.com and submit your Flash Games!

BBS Signature

Response to AS:Ground Movement 2007-03-09 19:03:09


Scratch that it was just a graphic glitch on my end.


Visit JackSmack.com and submit your Flash Games!

BBS Signature

Response to AS:Ground Movement 2007-03-09 19:23:46


Shit this thread is old


wat

Response to AS:Ground Movement 2007-03-09 19:53:09


That was a great help.

Response to AS:Ground Movement 2007-04-03 21:04:13


actually I did find one problem that I can't figure out.

If the user is walking diagonaly with two keys down and releases them both at the exact same time the walk cycle continues to play.

is there a quick work around for that?


Visit JackSmack.com and submit your Flash Games!

BBS Signature

Response to AS:Ground Movement 2007-04-07 17:42:19


At 4/3/07 09:04 PM, JackSmack wrote: actually I did find one problem that I can't figure out.

If the user is walking diagonaly with two keys down and releases them both at the exact same time the walk cycle continues to play.

is there a quick work around for that?

PLEASEPLEASE someone answer this

Response to AS:Ground Movement 2007-04-12 14:40:03


Hey, would it be possable to have a download link for the imageshack file?
Just curious =]
Ty btw<3


LOL @ this review

Great i love it. A must if you love blowin peoples heads off.

For game http://www.newgrounds.com/portal/vi ew/283047

Response to AS:Ground Movement 2007-04-12 19:16:06


Mmm.. Dunno why i was asking for a download o_O
All we need now is a tutorial for shooting and walls =]]]


LOL @ this review

Great i love it. A must if you love blowin peoples heads off.

For game http://www.newgrounds.com/portal/vi ew/283047

Response to AS:Ground Movement 2007-07-27 17:37:12


At 10/26/05 07:55 PM, Thomas wrote: Start off by adding the variables.

onClipEvent (load) {
speed = 5;
speed2 = 3;
scale = _xscale;
}

What do you mean adding the variables?....Where do i add that script? on the movie clip? on the frame of the movie clip?

I didn't really understand what you meant..

(I'm a huge noob..)