Be a Supporter!

AS: Basic Movement

  • 27,136 Views
  • 93 Replies
New Topic Respond to this Topic
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
AS: Basic Movement Feb. 10th, 2005 @ 04:58 PM Reply

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
JParadox
JParadox
  • Member since: Aug. 4, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Basic Movement Feb. 10th, 2005 @ 05:15 PM Reply

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
madmeater
madmeater
  • Member since: Mar. 1, 2004
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS: Basic Movement Feb. 10th, 2005 @ 06:03 PM Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Basic Movement Feb. 10th, 2005 @ 06:34 PM Reply

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
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Basic Movement Feb. 10th, 2005 @ 06:36 PM Reply

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
Deathcon7
Deathcon7
  • Member since: Oct. 1, 2003
  • Offline.
Forum Stats
Member
Level 21
Writer
Response to AS: Basic Movement Feb. 10th, 2005 @ 10:56 PM Reply

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.

Deathcon7
Deathcon7
  • Member since: Oct. 1, 2003
  • Offline.
Forum Stats
Member
Level 21
Writer
Response to AS: Basic Movement Feb. 10th, 2005 @ 10:57 PM Reply

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

JParadox
JParadox
  • Member since: Aug. 4, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Basic Movement Feb. 10th, 2005 @ 10:58 PM Reply

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

lol @ n00bulation.


BBS Signature
Deathcon7
Deathcon7
  • Member since: Oct. 1, 2003
  • Offline.
Forum Stats
Member
Level 21
Writer
Response to AS: Basic Movement Feb. 10th, 2005 @ 11:03 PM Reply

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*

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Basic Movement Feb. 11th, 2005 @ 09:09 AM Reply

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
gamatek
gamatek
  • Member since: Feb. 20, 2005
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Basic Movement Mar. 15th, 2005 @ 04:40 PM Reply

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

gamatek
gamatek
  • Member since: Feb. 20, 2005
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Basic Movement Mar. 15th, 2005 @ 06:47 PM Reply

any help?

Fury-X
Fury-X
  • Member since: Nov. 27, 2004
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Basic Movement May. 22nd, 2005 @ 12:53 AM Reply

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

Hoeloe
Hoeloe
  • Member since: Apr. 29, 2004
  • Offline.
Forum Stats
Member
Level 37
Game Developer
Response to AS: Basic Movement May. 24th, 2005 @ 03:01 PM Reply

wots the code for "e"?


Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------

BBS Signature
squirrelg0dsgay
squirrelg0dsgay
  • Member since: Mar. 11, 2005
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS: Basic Movement May. 24th, 2005 @ 03:33 PM Reply

me like scientests!

squirrelg0dsgay
squirrelg0dsgay
  • Member since: Mar. 11, 2005
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS: Basic Movement May. 24th, 2005 @ 03:35 PM Reply

better version

Hoeloe
Hoeloe
  • Member since: Apr. 29, 2004
  • Offline.
Forum Stats
Member
Level 37
Game Developer
Response to AS: Basic Movement Jun. 2nd, 2005 @ 01:01 PM Reply

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

AS: Basic Movement


Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------

BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Basic Movement Jun. 2nd, 2005 @ 02:02 PM Reply

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
JeremysFilms
JeremysFilms
  • Member since: Feb. 18, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Basic Movement Jun. 8th, 2005 @ 07:28 PM Reply

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?

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Basic Movement Jun. 8th, 2005 @ 07:35 PM Reply

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

Hoeloe
Hoeloe
  • Member since: Apr. 29, 2004
  • Offline.
Forum Stats
Member
Level 37
Game Developer
Response to AS: Basic Movement Jul. 2nd, 2005 @ 08:56 AM Reply

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


Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------

BBS Signature
aquaticmole
aquaticmole
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 29
Melancholy
Response to AS: Basic Movement Jul. 2nd, 2005 @ 08:57 AM Reply

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


aquaticmole.

BBS Signature
bloodmonkey
bloodmonkey
  • Member since: Feb. 10, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Basic Movement Jul. 2nd, 2005 @ 09:10 AM Reply

how do i make bullets

Rhinan
Rhinan
  • Member since: May. 19, 2005
  • Offline.
Forum Stats
Member
Level 15
Game Developer
Response to AS: Basic Movement Jul. 2nd, 2005 @ 05:21 PM Reply

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

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Basic Movement Jul. 2nd, 2005 @ 05:22 PM Reply

go to AS: Symbols

DarkJeroyd2000
DarkJeroyd2000
  • Member since: Oct. 3, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to AS: Basic Movement Jul. 14th, 2005 @ 05:40 PM Reply

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

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

Fbi-bp
Fbi-bp
  • Member since: Jun. 30, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Basic Movement Jul. 14th, 2005 @ 05:45 PM Reply

i learnd alot in this topic. thx

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Basic Movement Jul. 14th, 2005 @ 05:47 PM Reply

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
JCesta
JCesta
  • Member since: Jul. 8, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Basic Movement Aug. 1st, 2005 @ 05:28 PM Reply

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

Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to AS: Basic Movement Aug. 4th, 2005 @ 11:11 AM Reply

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

Am I right? :S


BBS Signature