Be a Supporter!

AS: Basic Movement

  • 27,415 Views
  • 93 Replies
New Topic Respond to this Topic
Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to AS: Basic Movement May. 12th, 2006 @ 12:05 PM Reply

Ah, dude, just use the documentation!


BBS Signature
KougaijiGyumao
KougaijiGyumao
  • Member since: May. 26, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Basic Movement May. 30th, 2006 @ 10:24 PM Reply

I tried using it, but it doesn't seem to work for me. I want it to work, but it won't. This is the AS I used.

onClipEvent(load){
speed=5; stop();
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){_x+=speed; gotoAndStop(42);}
if (Key.isDown(Key.DOWN)){_y+=speed; gotoAndStop(2);}
if (Key.isDown(Key.LEFT)){_x-=speed; gotoAndStop(41);}
if (Key.isDown(Key.UP)){_y-=speed; gotoAndStop(1);}
}

41 is walking left, and 42 is walking right. I haven't fixed the walking upwards and downwards.

KougaijiGyumao
KougaijiGyumao
  • Member since: May. 26, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Basic Movement Jun. 6th, 2006 @ 02:53 AM Reply

:Er, don't mind my last post, that was from my previous game. [didn't work out...]

Uhm, Can you guys help me? I used this AS and I modified some parts, and well... I can't seem to make it work...

Here's the wrong parts in my AS:
onClipEvent(load){
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 (Key.isDown(Key.17) && dir=1)
{_x-=speed; gotoAndPlay(15); dir=1;}
else if (Key.isDown(Key.17) && dir=0)
{_x-=speed; gotoAndPlay(5); dir=0;}
else { if (dir==0) {gotoAndStop(1);}else{gotoAndStop(4);}
}

sniffy-gerbil
sniffy-gerbil
  • Member since: Apr. 14, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Basic Movement Jun. 11th, 2006 @ 08:52 AM Reply

I like how you put down the number code for some of the keys. That's really helpful. Although someone gave me a flash number key generator which can be found here:
Key Generator

UnknownFear
UnknownFear
  • Member since: Feb. 27, 2004
  • Offline.
Forum Stats
Member
Level 37
Gamer
Response to AS: Basic Movement Jun. 24th, 2006 @ 04:15 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?

My guess is, when you let go of the key that moves the character, he stops...?

El-Presidente
El-Presidente
  • Member since: Jun. 2, 2005
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Basic Movement Jul. 20th, 2006 @ 08:13 PM Reply

To answer your question of "what the hell" those numbers mean, is that if you wanted to make a game and lets say you wanted to make your move key be D, then you would use the number for the actionscript, because there is no other code for the letter D. It's like the right arrow key is Key.RIGHT, this is Key(#). Hopefully that answers your quesoitn


MY E-PENIS IS BIGGER THAN YOURS
8=================================>
...and this is my fag...

BBS Signature
rootbeerfloat
rootbeerfloat
  • Member since: Feb. 2, 2005
  • Offline.
Forum Stats
Member
Level 12
Gamer
Response to AS: Basic Movement Jul. 20th, 2006 @ 08:23 PM Reply

At 2/10/05 04:58 PM, Denvish wrote: Basic Movement

Left, right, down, up, and diagonal movement

So is this coding for like a top looking down view? Or a side view?

HappilyNeverAfter
HappilyNeverAfter
  • Member since: Jul. 23, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Basic Movement Aug. 25th, 2006 @ 11:24 AM 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?

First Read To What He Was Saying It First :)

SYNXanimation
SYNXanimation
  • Member since: Apr. 30, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Basic Movement Nov. 25th, 2006 @ 07:33 AM Reply

iv read this forum and it helped me but can some tell me how to make a MC move Diagonal With out movein left, right, up and down.

itsjms
itsjms
  • Member since: Feb. 13, 2007
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Basic Movement Feb. 19th, 2007 @ 11:38 PM Reply

im making a game i need as for it to be able to stand on platofrms and the guy needs to change frames in his movie clip so he runs/jumps/stand still. stand still is frame 1 in the movie clip frame 2 is run and frame 3 is jump plz some1 write it


BBS Signature
Vega-034
Vega-034
  • Member since: Apr. 27, 2007
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Basic Movement Apr. 27th, 2007 @ 09:27 PM Reply

Umm... Yeah. This really is a great tutorial, but what if you are using ActionScript 3.0?
--btw total flash noob :)!

americanidiot2f
americanidiot2f
  • Member since: Nov. 25, 2006
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Basic Movement Aug. 23rd, 2007 @ 09:02 PM Reply

I made 4 frames, each one moving rite, down, left, up. Then I entered this code:
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);}
}
to the first MC on the first frame.
When I tested, all 4 frames were just going in order without me pressing any keys.
What did I do wrong?!


.

Cheektoghetto
Cheektoghetto
  • Member since: Jan. 27, 2007
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Basic Movement Aug. 23rd, 2007 @ 09:40 PM Reply

At 8/23/07 09:02 PM, americanidiot2f wrote:
to the first MC on the first frame.
When I tested, all 4 frames were just going in order without me pressing any keys.
What did I do wrong?!

Put A stop command on each main MC frame, and BTW, as far as I know, bumping topics that haven't been posted in, in like 4 months, is not cool.


BBS Signature
3pwood
3pwood
  • Member since: Aug. 19, 2007
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS: Basic Movement Aug. 25th, 2007 @ 08:44 AM Reply

nice :)
here is a code for walking and turning with animation in a side scroller:

onClipEvent(load){
walk=2
wrdown=2
wldown=2
scale=1
speed=5
}

onClipEvent(enterFrame){
if(Key.isDown(68)){ //notes "d" is down
wrdown=1

}
else{
if(wrdown==1){ //cheks if "d" was down before and switch to breathing if it is up
walk=2
wrdown=2
this.gotoAndPlay("brea")

}}

if(Key.isDown(68)&&(walk==2)){ //walks right

walk=1;
if(scale==2){
this._xscale=-this._xscale
scale=1
this.gotoAndPlay("turn")
this._x=this._x+speed

}
else{
this.gotoAndPlay("walk");
this._x=this._x+speed

}
}

if(Key.isDown(65)){ //notes "a" is down
wldown=1

}
else{
if(wldown==1){ //cheks if "a" was down before and switch to breathing if it is up
walk=2
wldown=2
this.gotoAndPlay("brea")

}}

if(Key.isDown(65)&&(walk==2)){ //walks left
walk=1;
if(scale==1){
this._xscale=-this._xscale
scale=2
this.gotoAndPlay("turn")
this._x=this._x-speed

}
else{
this.gotoAndPlay("walk");
this._x=this._x-speed

}
}

if((Key.isDown(68))&&(Key.isDown(65))){ //cancels walking in case of both keys pressed
this.gotoAndStop("brea");

}}

so here is the deal:
you need a movie clip (appeared here only as "this") with 3 animations:
1.breath -first frame of the animation named brea
2.turn (character drawn from front)-first frame of the animation named turn
3.walk- first frame of the animation named walk

you need all the animations to loop ( "gotoAndPlay(animation first frame's name)" at the end of the animation).

StealthBeast
StealthBeast
  • Member since: Feb. 2, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Basic Movement Aug. 30th, 2007 @ 06:07 PM Reply

Hey. I have no experiance in any programming language whatsoever. I want to learn actionscript, and I figure this is simple enough place to start.

Copy-pasted the code for directional orientation and movement, and it all works. As a simple test, i made it so when space is pressed, it goes to frame 5, which is just a red dot. Simple stuff.

I experimented with the concept of diagnol character orientation:

if (Key.isDown(Key.RIGHT and Key.Up)){_x+=speed; _y-=speed; gotoAndStop(6);}

My objective was, to add extra-orientation. Not just left, right, up and down, but also, upright. On frame 6, i drew an arrow pointing diagnally up-right. Naturally, I got error.

Why can't something like this be done? What is the correct way to do this?

StealthBeast
StealthBeast
  • Member since: Feb. 2, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Basic Movement Aug. 30th, 2007 @ 06:12 PM Reply

(Sorry, i fixed the typo, UP)

El-Presidente
El-Presidente
  • Member since: Jun. 2, 2005
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Basic Movement Aug. 30th, 2007 @ 06:16 PM Reply

Why post in here like years later. Anyways, it could be like this
if(Key.isDown(Key.UP)){
if(Key.isDown(Key.LEFT)){
you get up and left here...
}
}


MY E-PENIS IS BIGGER THAN YOURS
8=================================>
...and this is my fag...

BBS Signature
StealthBeast
StealthBeast
  • Member since: Feb. 2, 2004
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Basic Movement Aug. 30th, 2007 @ 06:21 PM Reply

At 8/30/07 06:16 PM, El-Presidente wrote: Why post in here like years later. Anyways, it could be like this
if(Key.isDown(Key.UP)){
if(Key.isDown(Key.LEFT)){
you get up and left here...
}
}

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(4);}
if (Key.isDown(Key.SPACE)){gotoAndStop(5);}
if (Key.isDown(Key.RIGHT)and Key.isDown(Key.UP)){gotoAndStop(6);}
if (Key.isDown(Key.RIGHT)and Key.isDown(Key.DOWN)){gotoAndStop(7);}
if (Key.isDown(Key.LEFT)and Key.isDown(Key.UP)){gotoAndStop(8);}
if (Key.isDown(Key.LEFT)and Key.isDown(Key.DOWN)){gotoAndStop(9);}
}

It's in perfect working order now ^_^ I'm surprised I didn't think of that...

Sorry about posting in here but I saw that it had been posted in a few times in the past few days and thought "why not?"

jakk22
jakk22
  • Member since: Jul. 12, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Basic Movement Aug. 30th, 2007 @ 06:34 PM Reply

yeah your the bomb with the tuts.

Dizeaze
Dizeaze
  • Member since: Dec. 21, 2007
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Basic Movement Dec. 24th, 2007 @ 03:33 AM Reply

what IS "AS"

It sounds interesting.


YOU GOT RICK-ROLLED!

fuck

Truls95
Truls95
  • Member since: Feb. 24, 2007
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to AS: Basic Movement Feb. 11th, 2008 @ 01:04 PM Reply

.. But Whats the Jump AS for it ?

Roachmins
Roachmins
  • Member since: Mar. 31, 2008
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: Basic Movement Oct. 16th, 2008 @ 07:47 PM Reply

This what people want in their games well I want to say that we want smoother beautiful walking that looks realistic on a flash game how do we make the most advance walking rpg game that can helps us learn quicker we need learn simple...

luigibro375
luigibro375
  • Member since: Jun. 9, 2008
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Basic Movement Dec. 26th, 2008 @ 01:35 AM Reply

At 2/10/05 04:58 PM, Denvish wrote: 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;
}

do i have to remember this all or something cuz i got a bad memory :C


cheesecake is a kind of cake that's not fluffy

catd77
catd77
  • Member since: Mar. 2, 2008
  • Offline.
Forum Stats
Member
Level 16
Programmer
Response to AS: Basic Movement Jan. 25th, 2009 @ 10:38 AM Reply

Thanks, really helped me.


BBS Signature
Zyphonee
Zyphonee
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to AS: Basic Movement Feb. 10th, 2009 @ 04:54 PM Reply

I actually used this code:

onClipEvent(load){
speed=5; stop(); dir=1;moving=0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){moving=1; dir=1;}
else if (Key.isDown(Key.DOWN)){moving=1; dir=2;}
else if (Key.isDown(Key.LEFT)){moving=1; dir=3;}
else if (Key.isDown(Key.UP)){moving=1; dir=4;}
else{moving=0;}
if(moving){
gotoAndStop(dir);
}else{
gotoAndStop(dir+4);
}
}
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;
}

Works perfectly, but you gotta follow the frames Denvish posted, I thought I'd post it here as without the second part, the code didn't work, or at least it didn't for me, as the character followed the cycles but didn't move.

GamingStuff
GamingStuff
  • Member since: Aug. 13, 2010
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Basic Movement Oct. 21st, 2010 @ 02:36 AM Reply

Ho can i stop it from going diagonal so i just have up down left and right. Cause i've got some sprite animations and the code makes it go diagonal and i dont want it. What do i do to it????


I am a new animator! Dont judge my bad Animations!!

GamingStuff
GamingStuff
  • Member since: Aug. 13, 2010
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Basic Movement Oct. 29th, 2010 @ 03:37 AM Reply

Please someone answer!! I will give you more information
This is for a game that i am making (its kinda a remake of Pokemon, for the people who cant get it or afford it) that has 4 directional sprite movement but i only want the sprite to go left, right, up, down not left up, right up, down left, down, right also.

PLEASE pwase pwase!!!!!!!!!!1


I am a new animator! Dont judge my bad Animations!!

Skeik-Sprite
Skeik-Sprite
  • Member since: Jun. 19, 2005
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to AS: Basic Movement Oct. 29th, 2010 @ 12:21 PM Reply

You probably should've made a new thread to ask your question.

But what you need to do is use an if..else statement to make sure the player can only move in one direction at once. An example of this in AS2 would be

if(Key.isDown(Key.LEFT)){
_x-=2
}else if(Key.isDown(Key.RIGHT)){
_x+=2
}else if(Key.isDown(Key.UP)){
_y-=2
}else if(Key.isDown(Key.DOWN)){
_y+=2
}

Or something to that effect. That way the character can only move in one direction at once.

GamingStuff
GamingStuff
  • Member since: Aug. 13, 2010
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Basic Movement Nov. 3rd, 2010 @ 06:49 AM Reply

Thankx but it didn't work here my code atm with your code added to it

onClipEvent(load){
speed=6;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
this._y-=speed;
this.gotoAndStop(5);
}
if(Key.isDown(Key.DOWN)){
this._y+=speed;
this.gotoAndStop(6);
}
if(Key.isDown(Key.RIGHT)){
this._x+=speed;
this.gotoAndStop(7);
}
if(Key.isDown(Key.LEFT)){
this._x-=speed;
this.gotoAndStop(8);
}
if(Key.isDown(Key.LEFT)){
_x-=2
}else if(Key.isDown(Key.RIGHT)){
_x+=2
}else if(Key.isDown(Key.UP)){
_y-=2
}else if(Key.isDown(Key.DOWN)){
_y+=2
}
}

It still wont work!!
I'm very frustrated Right now


I am a new animator! Dont judge my bad Animations!!

DannyDaNinja
DannyDaNinja
  • Member since: Mar. 14, 2010
  • Offline.
Forum Stats
Member
Level 04
Game Developer
Response to AS: Basic Movement Nov. 3rd, 2010 @ 07:12 AM Reply

Sorry for the noobyness but IS THIS ACTIONSCIPT 1.0!?!?!


Trying to post in topics that have no replies. Trust me it's a horrible feeling when nobody replies to your topic :{