00:00
00:00
Newgrounds Background Image Theme

sereneFalconer 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: Basic Movement

32,726 Views | 92 Replies
New Topic Respond to this Topic

Response to AS: Basic Movement 2006-05-30 22:24:04


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.

Response to AS: Basic Movement 2006-06-06 02:53:13


: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);}
}

Response to AS: Basic Movement 2006-06-11 08:52:04


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

Response to AS: Basic Movement 2006-06-24 16:15:50


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...?

Response to AS: Basic Movement 2006-07-20 20:13:49


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

Response to AS: Basic Movement 2006-07-20 20:23:50


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?

Response to AS: Basic Movement 2006-08-25 11:24:33


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 :)

Response to AS: Basic Movement 2006-11-25 07:33:07


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.

Response to AS: Basic Movement 2007-02-19 23:38:09


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

Response to AS: Basic Movement 2007-04-27 21:27:25


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

Response to AS: Basic Movement 2007-08-23 21:02:52


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?!


.

Response to AS: Basic Movement 2007-08-23 21:40:59


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

Response to AS: Basic Movement 2007-08-25 08:44:31


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).

Response to AS: Basic Movement 2007-08-30 18:07:35


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?

Response to AS: Basic Movement 2007-08-30 18:12:07


(Sorry, i fixed the typo, UP)

Response to AS: Basic Movement 2007-08-30 18:16:36


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

Response to AS: Basic Movement 2007-08-30 18:21:09


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?"

Response to AS: Basic Movement 2007-08-30 18:34:09


yeah your the bomb with the tuts.

Response to AS: Basic Movement 2007-12-24 03:33:43


what IS "AS"

It sounds interesting.


YOU GOT RICK-ROLLED!

fuck

Response to AS: Basic Movement 2008-02-11 13:04:15


.. But Whats the Jump AS for it ?

Response to AS: Basic Movement 2008-10-16 19:47:32


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...

Response to AS: Basic Movement 2008-12-26 01:35:31


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

Response to AS: Basic Movement 2009-01-25 10:38:08


Thanks, really helped me.


BBS Signature

Response to AS: Basic Movement 2009-02-10 16:54:14


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.

Response to AS: Basic Movement 2010-10-21 02:36:18


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!!

Response to AS: Basic Movement 2010-10-29 03:37:44


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!!

Response to AS: Basic Movement 2010-10-29 12:21:48


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.

Response to AS: Basic Movement 2010-11-03 06:49:20


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!!

Response to AS: Basic Movement 2010-11-03 07:12:36


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 :{

Response to AS: Basic Movement 2010-11-03 11:07:21


At 11/3/10 06:49 AM, GamingStuff wrote: 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

Once again you should probably make your own topic, but you can't just expect to add the code I typed up to the end of the code you already had and expect it work. If you don't know things as basic as these you should probably go back and look up if statements and reread the topic.