View Full Version : Why is my Penguin Fat after changing direction using "scaleX"
999chris
March 16th, 2010, 11:57 AM
My Code:
var facing:int = 1;
if (xspeed<0) {
walker();
hero.scaleX=- facing;
}
if (xspeed>0) {
walker();
hero.scaleX=facing;
}
I have my "hero" as a MovieClip that I placed on the stage, and resized. But when he changes direction his width reverts back to the original thats within the MovieClip. Any Ideas?
Chris
Shaedo
March 16th, 2010, 12:38 PM
change
hero.scaleX=- facing;
to
hero.scaleX=- hero.scaleX;
EDIT or better yet change :
var facing:int = 1;
to
var facing:int = hero.scaleX;
To understand what is going on have a look at what changing the scaleX does:
var s:Sprite = new Sprite;
s.graphics.beginFill(0x00FF00);
s.graphics.drawRect(0,0,50,50);
s.x=s.y=100;
addChild(s);
trace(s.width,s.scaleX);// 50 1
s.scaleX = 2;
trace(s.width,s.scaleX);// 100 2
s.scaleX = -1;
trace(s.width,s.scaleX); // 50 -1
s.scaleX = 2;
trace(s.width,s.scaleX); // 100 2
s.scaleX= -s.scaleX;
trace(s.width,s.scaleX); // 100 -2
more info here:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/fl/core/UIComponent.html#scaleX
Scythe
March 17th, 2010, 03:21 AM
What Shaedo is getting at here is that if you've resized your movieclip as you say you have, its scaleX is already going to be set to something that's not 1 or -1. So your resizing will be undone by your code.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.