00:00
00:00

AS: Basic Movement

30,531 Views | 92 Replies
New Topic Respond to this Topic

AS: Basic Movement 2005-02-10 16:58:25


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

Response to AS: Basic Movement 2005-02-10 17:15:10


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

Response to AS: Basic Movement 2005-02-10 18:03:56


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

Response to AS: Basic Movement 2005-02-10 18:34:10


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

Response to AS: Basic Movement 2005-02-10 18:36:59


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

Response to AS: Basic Movement 2005-02-10 22:56:27


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.

Response to AS: Basic Movement 2005-02-10 22:57:33


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

Response to AS: Basic Movement 2005-02-10 22:58:49


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

lol @ n00bulation.


BBS Signature

Response to AS: Basic Movement 2005-02-10 23:03:29


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*

Response to AS: Basic Movement 2005-02-11 09:09:04


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

Response to AS: Basic Movement 2005-03-15 16:40:21


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

Response to AS: Basic Movement 2005-03-15 18:47:04


any help?

Response to AS: Basic Movement 2005-05-22 00:53:02


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

Response to AS: Basic Movement 2005-05-24 15:01:01


wots the code for "e"?


BBS Signature

Response to AS: Basic Movement 2005-05-24 15:33:10


me like scientests!

Response to AS: Basic Movement 2005-05-24 15:35:01


better version

Response to AS: Basic Movement 2005-06-02 13:01:01


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

AS: Basic Movement


BBS Signature

Response to AS: Basic Movement 2005-06-02 14:02:41


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


BBS Signature

Response to AS: Basic Movement 2005-06-08 19:28:46


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?

Response to AS: Basic Movement 2005-06-08 19:35:34


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

Response to AS: Basic Movement 2005-07-02 08:56:11


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


BBS Signature

Response to AS: Basic Movement 2005-07-02 08:57:18


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


aquaticmole.

BBS Signature

Response to AS: Basic Movement 2005-07-02 09:10:50


how do i make bullets

Response to AS: Basic Movement 2005-07-02 17:21:50


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

Response to AS: Basic Movement 2005-07-02 17:22:46


go to AS: Symbols

Response to AS: Basic Movement 2005-07-14 17:40:41


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

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

Response to AS: Basic Movement 2005-07-14 17:45:16


i learnd alot in this topic. thx

Response to AS: Basic Movement 2005-07-14 17:47:38


At 7/14/05 05:40 PM, DarkJeroyd2000 wrote:
At 2/10/05 04:58 PM, Denvish wrote:
speed=10; stop();
What does speed=10; stop(); mean?

For "speed = 10;" , have a look at my Variables tutorial


BBS Signature

Response to AS: Basic Movement 2005-08-01 17:28:47


At 2/10/05 06:03 PM, madmeater wrote: 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

dam right

Response to AS: Basic Movement 2005-08-04 11:11:29


"speed" is a variable you set a value for, stop tells the movie clip to stop playing.

Am I right? :S


BBS Signature