PDA

View Full Version : Quick code fix needed, probably real simple



Frey
March 12th, 2009, 08:33 PM
Right basically I have a character and a background. The background scrolls as you press left or right on keyboard to create the illusion of movement.

I want the character to flip when you change from holding down left to right and vice versa, but when I do the following code it doubles the size of the character once and then it stays. It flips fine but in the transformed fat size. Any ideas?

Here's the code:


var mySpeed:Number = 10;

function keyIsDown(evt:KeyboardEvent):void{

if(evt.keyCode==Keyboard.RIGHT){
walkingPlane_mc.x+=mySpeed;
greyCharacter_mc.scaleX=-1;
}

if(evt.keyCode==Keyboard.LEFT){
walkingPlane_mc.x-=mySpeed;
greyCharacter_mc.scaleX=+1;
}
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyIsDown);

phelpsi
March 13th, 2009, 06:00 PM
I had good luck using:

_mc.scaleX *= -1;

for all cases. Flipped my Sprites around the 0-point, so you'll need to do some alignment to keep your character in the same place after he turns.