00:00
00:00
Newgrounds Background Image Theme

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

How do i make a character play an animation when they are running and holding space?

150 Views | 1 Reply
New Topic Respond to this Topic

I am trying to make a player change to a running and shooting animation when the spacebar is down and they are moving


onClipEvent (load) {

var ground:MovieClip = _root.ground;

var grav:Number = 0;

var gravity:Number = 2;

var speed:Number = 28;

var maxJump:Number = -24;

var CrouchLeap:Number = 42;

var touchingGround:Boolean = false;

scale = _xscale;

}

onClipEvent (enterFrame) {

_y += grav;

grav += gravity;

while (ground.hitTest (_x, _y, true))

{

_y -= gravity;

grav = 0;

}

if (ground.hitTest (_x, _y + 5, true))

{

touchingGround = true;

}

else

{

touchingGround = false;

}

if (Key.isDown (Key.LEFT))

{

_xscale = -scale;

_x -= speed;

this.gotoAndStop (2);

}

if (Key.isDown (Key.RIGHT))

{

_xscale = +scale;

_x += speed;

this.gotoAndStop (2);

}

if (Key.isDown (Key.SPACE))

{

this.gotoAndStop (5);

}

if (Key.isDown (Key.UP) && touchingGround)

{

grav = maxJump;

this.gotoAndStop (3);

}

if (Key.isDown (Key.DOWN) && touchingGround)

{

this.gotoAndStop (4);

}

if (ground.hitTest (_x + (_width / 2), _y - (_height / 2), true))

{

_x -= speed;

}

if (ground.hitTest (_x - (_width / 2), _y - (_height / 2), true))

{

_x += speed;

}

if (ground.hitTest (_x, _y - (height), true))

{

grav = 3;

}

if (_root.vcam.hp._currentframe == 101)

{

speed = 0;

maxJump = 0;

this.gotoAndStop (6);

}

}

onClipEvent (keyUp) {

this.gotoAndStop (1);

}


this is the code, it is in actionscript 2


You'll need to:

  1. set a flag (e.g. running) to true if the player is pressing either the left or the right key
  2. if the running flag is true, and if the space key is pressed, then play the animation (i.e. go to a frame)
  3. if and only if the above conditions are not satisfied, then check whether the left/right/space key is pressed and play the animation for those keys respectively.

Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature