Forum Topic: AS: Basic Movement

(21,090 views • 88 replies)

This topic is 3 pages long. [ 1 | 2 | 3 ]

<< < > >>
None

Denvish

Reply To Post Reply & Quote

Posted at: 2/10/05 04:58 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,229

Basic Movement

Left, right, down, up, and diagonal movement

On the main stage, select the MC you wish to make move
Add Actions:

onClipEvent(load){
speed=10; stop();
}
onClipEvent (enterFrame) {
_x+=Key.isDown(Key.RIGHT)*speed;
_x-=Key.isDown(Key.LEFT)*speed;
_y+=Key.isDown(Key.DOWN)*speed;
_y-=Key.isDown(Key.UP)*speed;
}

Unfortunately, this one doesn't allow for changing the orientation (eg walking)... so

Left, right, down, up movement with orientation

Create a new MC with 4 frames.
On the first frame, add your character walking right.
On the second frame, add your character walking down.
Third frame, left. Fourth frame, up.

Put the MC on the stage and add these actions:
onClipEvent(load){
speed=10; stop();
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){_x+=speed; gotoAndStop(1);}
if (Key.isDown(Key.DOWN)){_y+=speed; gotoAndStop(2);}
if (Key.isDown(Key.LEFT)){_x-=speed; gotoAndStop(3);}
if (Key.isDown(Key.UP)){_y-=speed; gotoAndStop(1);}
}

---------------------------------

If you wish to use the WASD keys, the keycodes are:

WASD -- ARROWS -- A.KEYS
- (68) ------ (39) ------ (Key.RIGHT)
- (65) ------ (37) ------ (Key.LEFT)
- (87) ------ (38) ------ (Key.UP)
- (83) ------ (40) ------ (Key.DOWN)

Use them like this:
_x+=Key.isDown(39)
or
if (Key.isDown(39)){_x+=speed;}

Other useful ones:

SPACE -------- (32)
ALT ------------ (18)
ENTER -------- (13)
BACKSPACE --- (8)
SHIFT --------- (16)
Z --------------- (90)
X --------------- (88)
C -------------- (67)

- - Flash - Music - Images - -

BBS Signature

None

JParadox

Reply To Post Reply & Quote

Posted at: 2/10/05 05:15 PM

JParadox LIGHT LEVEL 20

Sign-Up: 08/04/04

Posts: 2,870

Denvish.

My anti drug.

Sweet job man, I learned a few things myself.

I hope this and your many other text tutorials help all in need.

BBS Signature

None

madmeater

Reply To Post Reply & Quote

Posted at: 2/10/05 06:03 PM

madmeater LIGHT LEVEL 05

Sign-Up: 03/01/04

Posts: 65

omg my saviour! i am the ultimate n00b wen it comes to AS but this will allow me to make a crude "game" to make my friends laugh =P


None

Denvish

Reply To Post Reply & Quote

Posted at: 2/10/05 06:34 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,229

Basic side-scroller (walking) movement

The variable 'dir' just holds the direction in which the character is moving, so he knows which direction to face when stopped

onClipEvent(load){
speed=10; stop(); dir=0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){
_x+=speed; gotoAndStop(2); dir=0;
}else if (Key.isDown(Key.LEFT)){
_x-=speed; gotoAndStop(3); dir=1;
}else{
if (dir==0){
gotoAndStop(1);
}else{
gotoAndStop(4);
}
}
}

- - Flash - Music - Images - -

BBS Signature

None

Denvish

Reply To Post Reply & Quote

Posted at: 2/10/05 06:36 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,229

At 2/10/05 06:34 PM, Denvish wrote: Basic side-scroller (walking) movement

That snippet assumes that frame 1 is stationary facing right, frame 2 is moving right, frame 3 is moving left, frame 4 is stationary facing left. Don't ask why they're in that order... ;)

- - Flash - Music - Images - -

BBS Signature

None

Deathcon7

Reply To Post Reply & Quote

Posted at: 2/10/05 10:56 PM

Deathcon7 NEUTRAL LEVEL 21

Sign-Up: 10/01/03

Posts: 5,838

for(i=0;i<numPlats;i++){
if(this.hitTest(_root["plat"+i])){
this.jump = false;
}
}

This is a really basic multi-object hitTester. What it does is it goes through and checks to see if the hero is hitting plat0, plat1, plat2, etc. and stops the character's jump if he is touching the platform. All you have to do is put this on the hero mc's enterFrame handler, then rename ALL the platforms according to this pattern: plat0, plat1, plat2, plat3, plat4, plat5... Then, on the hero, create a numPlats variable and set it equal to the number of platforms on the stage.


None

Deathcon7

Reply To Post Reply & Quote

Posted at: 2/10/05 10:57 PM

Deathcon7 NEUTRAL LEVEL 21

Sign-Up: 10/01/03

Posts: 5,838

Sorry guys, I n00bulated. The above code is an addition to the Side-Scroller tutorialette that Denvish wrote (2 posts up).


None

JParadox

Reply To Post Reply & Quote

Posted at: 2/10/05 10:58 PM

JParadox LIGHT LEVEL 20

Sign-Up: 08/04/04

Posts: 2,870

At 2/10/05 10:57 PM, Deathcon7 wrote: Sorry guys, I n00bulated.

lol @ n00bulation.

BBS Signature

None

Deathcon7

Reply To Post Reply & Quote

Posted at: 2/10/05 11:03 PM

Deathcon7 NEUTRAL LEVEL 21

Sign-Up: 10/01/03

Posts: 5,838

At 2/10/05 10:58 PM, -JParodox- wrote:
At 2/10/05 10:57 PM, Deathcon7 wrote: Sorry guys, I n00bulated.
lol @ n00bulation.

NO!
*Artery Clogs*
*Dies*


None

Denvish

Reply To Post Reply & Quote

Posted at: 2/11/05 09:09 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,229

At 2/10/05 11:03 PM, Deathcon7 wrote: NO!
*Artery Clogs*
*Dies*

Heh. Thanks for the input me ol' china. I'm probably going to a jumping/gravity thread at some point, your snippet will probably suit that or the hitTest one better. But it's all good.

- - Flash - Music - Images - -

BBS Signature

None

gamatek

Reply To Post Reply & Quote

Posted at: 3/15/05 04:40 PM

gamatek NEUTRAL LEVEL 01

Sign-Up: 02/20/05

Posts: 30

see now the thing is that if I put make it so the character attacks when the user clicks D it wont work, here is the code I put for the attack,Key Up being the attack key, but its not working

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_x += speed;
gotoAndStop(5);
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
gotoAndStop(2);
dir = 0;
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
gotoAndStop(3);
dir = 1;
} else {
if (dir == 0) {
gotoAndStop(1);
} else {
gotoAndStop(4);
}
}
}

any help


None

mofomojo

Reply To Post Reply & Quote

Posted at: 3/15/05 04:41 PM

mofomojo EVIL LEVEL 16

Sign-Up: 04/06/04

Posts: 6,178

Thanks Denvish for the code, but its best to learn it, not copy it. So I know what the hell I am doing.


None

gamatek

Reply To Post Reply & Quote

Posted at: 3/15/05 06:47 PM

gamatek NEUTRAL LEVEL 01

Sign-Up: 02/20/05

Posts: 30

any help?


None

mofomojo

Reply To Post Reply & Quote

Posted at: 5/22/05 12:48 AM

mofomojo EVIL LEVEL 16

Sign-Up: 04/06/04

Posts: 6,178

I know this thread is a bit outdated..

but what does the multiplier thingy for..

i dont get that..


None

Fury-X

Reply To Post Reply & Quote

Posted at: 5/22/05 12:53 AM

Fury-X LIGHT LEVEL 07

Sign-Up: 11/27/04

Posts: 1,125

You are quite the useful man, my good mod Denvish. Thanks for this!


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/24/05 03:01 PM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 5,013

wots the code for "e"?

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

Happy

squirrelg0dsgay

Reply To Post Reply & Quote

Posted at: 5/24/05 03:33 PM

squirrelg0dsgay EVIL LEVEL 05

Sign-Up: 03/11/05

Posts: 83

me like scientests!


Happy

squirrelg0dsgay

Reply To Post Reply & Quote

Posted at: 5/24/05 03:35 PM

squirrelg0dsgay EVIL LEVEL 05

Sign-Up: 03/11/05

Posts: 83

better version


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 6/2/05 01:01 PM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 5,013

wot is teh code for n + b?
+ heres a chicken 4 all u chicken fans!

AS: Basic Movement

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 6/2/05 02:02 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

There is a tutorial similiar to this one in my forum,made by DEADSIM.At least threads can't die in my foeum :D


Shouting

ApeLord

Reply To Post Reply & Quote

Posted at: 6/2/05 02:31 PM

ApeLord EVIL LEVEL 15

Sign-Up: 12/24/04

Posts: 1,559

Thanks a lot man!


Questioning

JeremysFilms

Reply To Post Reply & Quote

Posted at: 6/8/05 07:28 PM

JeremysFilms NEUTRAL LEVEL 17

Sign-Up: 02/18/05

Posts: 1,522

How do i make checkboard movement? like in the game frogger? so that rather than him moving smoothly he takes big movements at a time, but not right away, so even when holding down the arrow key, he doesnt keep moving super fast, it takes like a second between eahc move?


None

fwe

Reply To Post Reply & Quote

Posted at: 6/8/05 07:35 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,361

www.asciitable.com

I don't know n and b by heart, but i know e is 69. Or is it 65? One of those, for sure.

wtfbbqhax


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 7/2/05 08:56 AM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 5,013

wots a and s, cos i need them 4 my new game

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

Questioning

aquaticmole

Reply To Post Reply & Quote

Posted at: 7/2/05 08:57 AM

aquaticmole LIGHT LEVEL 28

Sign-Up: 02/10/05

Posts: 7,879

how can i make my mouse extend only a certain radios around my guy???

aquaticmole.

BBS Signature

None

bloodmonkey

Reply To Post Reply & Quote

Posted at: 7/2/05 09:10 AM

bloodmonkey EVIL LEVEL 10

Sign-Up: 02/10/05

Posts: 478

how do i make bullets


Thinking

Rhinan

Reply To Post Reply & Quote

Posted at: 7/2/05 05:21 PM

Rhinan EVIL LEVEL 15

Sign-Up: 05/19/05

Posts: 563

you guys still don't help me, i need to create a singel button, that's all i need
please help me with it, and don't just give the code/script, but explain to me please

Thanks already, and very much if it works ;D


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/2/05 05:22 PM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

go to AS: Symbols


None

DarkJeroyd2000

Reply To Post Reply & Quote

Posted at: 7/14/05 05:40 PM

DarkJeroyd2000 LIGHT LEVEL 16

Sign-Up: 10/03/04

Posts: 265

At 2/10/05 04:58 PM, Denvish wrote:
speed=10; stop();

What does speed=10; stop(); mean?


None

Fbi-bp

Reply To Post Reply & Quote

Posted at: 7/14/05 05:45 PM

Fbi-bp EVIL LEVEL 11

Sign-Up: 06/30/05

Posts: 56

i learnd alot in this topic. thx


All times are Eastern Standard Time (GMT -5) | Current Time: 02:20 PM

<< Back

This topic is 3 pages long. [ 1 | 2 | 3 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!