Be a Supporter!

Actionscript 2: Arrow Keys Help

  • 236 Views
  • 5 Replies
New Topic Respond to this Topic
Bobhead202
Bobhead202
  • Member since: Dec. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Actionscript 2: Arrow Keys Help 2010-12-03 23:28:47 Reply

Hello. I cannot figure out how I would create something so when you press an arrow key, a character changes what it looks like. For example, when you press right the character goes looks to its right, and vice versa for left. I have tried making multiple frames in the Movie Clip but it still isn't working. Please help!

jeremynative
jeremynative
  • Member since: Nov. 30, 2010
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Actionscript 2: Arrow Keys Help 2010-12-03 23:36:05 Reply

If you post your FLA I can do a sample and write comments next to the code.

Kevin
Kevin
  • Member since: Jan. 5, 2008
  • Offline.
Forum Stats
Member
Level 36
Melancholy
Response to Actionscript 2: Arrow Keys Help 2010-12-03 23:58:21 Reply

if(Key.isDown(Key.RIGHT)){
    this._xscale *= -1;
}
and vice versa for left.

Something like that.


BBS Signature
IndigenousDigitalist
IndigenousDigitalist
  • Member since: Sep. 24, 2010
  • Offline.
Forum Stats
Member
Level 13
Game Developer
Response to Actionscript 2: Arrow Keys Help 2010-12-04 08:25:44 Reply

At 12/3/10 11:58 PM, Kevin wrote: if(Key.isDown(Key.RIGHT)){
this._xscale *= -1;
}

and vice versa for left.
Something like that.

An easier way to do it would be just:

if(Key.isDown(Key.RIGHT)){
this._x+=5;
}

BBS Signature
CyberXR
CyberXR
  • Member since: Aug. 22, 2008
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Actionscript 2: Arrow Keys Help 2010-12-04 08:36:22 Reply

At 12/3/10 11:58 PM, Kevin wrote: if(Key.isDown(Key.RIGHT)){
this._xscale *= -1;
}

and vice versa for left.
Something like that.

Yeah! Imagine that you change the xscale of the character from positive 100% to negative 100%. This will make him turn around


Check out the coolest Donkey Kong Game on NG!
http://www.newgrounds.com/portal/vi ew/459064
100 posts @ Posted at: 9/15/08 07:36 AM http://www.newgrounds.com/bbs/topic /969232

Jin
Jin
  • Member since: Sep. 9, 2006
  • Offline.
Forum Stats
Supporter
Level 50
Blank Slate
Response to Actionscript 2: Arrow Keys Help 2010-12-04 09:45:48 Reply

Kevin, that'll make the movieclip flip constantly.

var _faceLeft:Number = this._xscale;

onEnterFrame = function() {
	if(Key.isDown(Key.RIGHT)){
		this._xscale = -_faceLeft;
	}
}

BBS Signature