00:00
00:00
Newgrounds Background Image Theme

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

AS2 Moving animation problem.

709 Views | 8 Replies
New Topic Respond to this Topic

AS2 Moving animation problem. 2013-02-06 11:54:23


I really need help i have tried to fix this problem and tried a lot of different solutions but none of them working.
I have this code for my character:

onClipEvent (enterFrame) {
radius =  _width/2;
if(Key.isDown(Key.UP)){
this._y -= 10;
this.head.gotoAndStop(3);
this.gotoAndPlay(2);
}
if(!Key.isDown(Key.UP)){
	this.gotoAndStop(1);
}

if(Key.isDown(Key.DOWN)){
this._y += 10;
this.head.gotoAndStop(1);
this.gotoAndPlay(2);
} 
if(!Key.isDown(Key.DOWN)){
	this.gotoAndStop(1);
}

if(Key.isDown(Key.LEFT)){
this._x -= 10;
this.head.gotoAndStop(2);
this.gotoAndPlay(2);
} 
if(!Key.isDown(Key.LEFT)){
	this.gotoAndStop(1);
}

if(Key.isDown(Key.RIGHT)){
this._x += 10;
this.head.gotoAndStop(4);
this.gotoAndPlay(2);
}
if(!Key.isDown(Key.RIGHT)){
	this.gotoAndStop(1);
}

while (_root.wall.hitTest (this._x, this._y+radius, true)){
this._y--;
}
while (_root.wall.hitTest (this._x, this._y-radius, true)){
this._y++;
}
while (_root.wall.hitTest (this._x-radius, this._y, true)){
this._x++;
}
while (_root.wall.hitTest (this._x+radius, this._y, true)){
this._x--;
}
}

I can move the char. around and all that but the walking animation won't play.
Any one help with this problem.
Thanks.

Response to AS2 Moving animation problem. 2013-02-06 12:31:07


looking at this code certainly takes me back.

do yourself a favor and learn AS3.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to AS2 Moving animation problem. 2013-02-06 12:36:05


Your issue is likely that you are telling your clip to gotoAndPlay every frame. A quick fix would be to add labels to your animations, and check if (this.currentLabel != "animationLabelName"). That way it will notice that it's playing the animation, and will not reset it each time.

At 2/6/13 12:31 PM, egg82 wrote: do yourself a favor and learn AS3.

I second this comment.

Response to AS2 Moving animation problem. 2013-02-06 13:59:08


At 2/6/13 12:36 PM, Mattster wrote: Your issue is likely that you are telling your clip to gotoAndPlay every frame. A quick fix would be to add labels to your animations, and check if (this.currentLabel != "animationLabelName"). That way it will notice that it's playing the animation, and will not reset it each time.

Can't get it to work.

Response to AS2 Moving animation problem. 2013-02-06 14:57:54


At 2/6/13 01:59 PM, WhaleMan wrote:
At 2/6/13 12:36 PM, Mattster wrote: Your issue is likely that you are telling your clip to gotoAndPlay every frame. A quick fix would be to add labels to your animations, and check if (this.currentLabel != "animationLabelName"). That way it will notice that it's playing the animation, and will not reset it each time.
Can't get it to work.

Of course, in AS1 there is no currentLabel property, you have to set your own, AS3 already give you that. Another motive which you should change to AS3.

Response to AS2 Moving animation problem. 2013-02-06 15:07:13


At 2/6/13 02:57 PM, Spysociety wrote:
Of course, in AS1 there is no currentLabel property, you have to set your own, AS3 already give you that. Another motive which you should change to AS3.

I don't want to change to as3 now

Response to AS2 Moving animation problem. 2013-02-06 15:12:34


At 2/6/13 03:07 PM, WhaleMan wrote: I don't want to change to as3 now

peer pressure says you will.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to AS2 Moving animation problem. 2013-02-06 18:11:52


At 2/6/13 11:54 AM, WhaleMan wrote: I really need help i have tried to fix this problem and tried a lot of different solutions but none of them working.
I can move the char. around and all that but the walking animation won't play.
Any one help with this problem.
Thanks.

You need manage the state and fix your key logic. When holding down the an arrow key, it will gotoAndPlay(2) every frame, effectively stopping the animation from ever getting past the first frame. In order to fix this, create a boolean variable to represent whether you are already playing the animation. However, even if you were doing this, the animation would only play when you are holding down the right arrow key because you have a condition that takes the clip back to the first frame if the right key is not down. You could check whether any of the keys are down or just flip another boolean if one is down. Also, instead of checking whether something is false after you just checked if is true, you can use an else statement.

onClipEvent(load)
{
	var standing:Boolean = true;
	var keysDown:Boolean = false;
}
onClipEvent (enterFrame) {
	radius =  _width/2;
	keysDown = false;
	if(Key.isDown(Key.UP)){
		keysDown = true;
		this._y -= 10;
		this.head.gotoAndStop(3);
		if (standing){
			gotoAndPlay(2);
			standing = false;
		}
	}
	if(Key.isDown(Key.DOWN)){
		keysDown = true;
		this._y += 10;
		this.head.gotoAndStop(1);
		if (standing){
			gotoAndPlay(2);
			standing = false;
		}
	}
	if(Key.isDown(Key.LEFT)){
		keysDown = true;
		this._x -= 10;
		this.head.gotoAndStop(2);
		if (standing){
			gotoAndPlay(2);
			standing = false;
		}
	}
	if(Key.isDown(Key.RIGHT)){
		keysDown = true;
		this._x += 10;
		this.head.gotoAndStop(4);
		if (standing){
			gotoAndPlay(2);
			standing = false;
		}
	}
	if (!keysDown)
	{
		this.gotoAndStop(1);
		standing = true;
	}
	
	while (_root.wall.hitTest (this._x, this._y+radius, true)){
		this._y--;
	}
	while (_root.wall.hitTest (this._x, this._y-radius, true)){
		this._y++;
	}
	while (_root.wall.hitTest (this._x-radius, this._y, true)){
		this._x++;
	}
	while (_root.wall.hitTest (this._x+radius, this._y, true)){
		this._x--;
	}
}

BBS Signature

Response to AS2 Moving animation problem. 2013-02-07 12:59:25


At 2/6/13 06:11 PM, Tree-SkyLark-BCE wrote: You need manage the state and fix your key logic. When holding down the an arrow key, it will gotoAndPlay(2) every frame,

Thank you it really helped and got it to work with some tweaks.