Jump to content
Search Community

cant get scale to work

bandy test
Moderator Tag

Recommended Posts

I am embarrassed to post this but have looked high and low and can't find an answer.

I simple want a sprite to grow from a small size to a large size while staying in the same place. Even in the simplest code, the sprite changes position through the tween. The different position seems to depend on whether scale is under 1, (e.g.: 0.4) or over 1. The sprite then moves to the final position. But the trace statements say the position is the same.

Also, the sprite won't scale up if the number is over 1; it will only scale down for number less than one. I must be doing something very basically wrong. Please help.

 

Flex Builder 4 code:

 

package

{

 

import com.greensock.*;

import com.greensock.data.*;

import com.greensock.easing.*;

 

import flash.display.MovieClip;

import flash.display.Sprite;

import flash.events.Event;

 

public class testtween extends Sprite

{

private var mySprite:Sprite;

 

public function testtween()

{

mySprite = new MovieClip();

mySprite.graphics.beginFill(0x0000ff);

mySprite.graphics.drawRect(200,200,30,30);

mySprite.graphics.endFill();

mySprite.addEventListener(Event.ADDED_TO_STAGE, doTween);

addChild(mySprite);

trace(mySprite.x + "beforeX");

trace(mySprite.width + "beforewidth");

 

}

public function doTween(e:Event):void

 

{

TweenLite.to(mySprite,1,{x:200,y:200,scaleX:.9, scaleY:.9});

 

 

//TweenLite.to(mySprite,5,new TweenLiteVars().prop("height",70,true).prop("x",0).onComplete(finish).ease(Linear.easeout));

 

}

 

public function finish():void

 

{

trace(mySprite.x + "afterX");

trace(mySprite.width + "afterwidth");

}

}

 

}

Link to comment
Share on other sites

hmm, from what you are saying, you DON'T want my sprite to move yet your code:

 

TweenLite.to(mySprite,1,{x:200,y:200,scaleX:.9, scaleY:.9});

 

is tweening the x and y properties? that probably shouldn't be in there.

 

mySprite should have an x and y of 0 when it is added to the stage and you are telling it to move to x:200 y:200.

 

from what you posted your tween is working as expected.

 

what value do you get for mySprite.x + "afterX"? 200?

Link to comment
Share on other sites

Carl, thanks for your reply.

Actually I put the x and y values in there as a way to keep them there, as they are set at 200,200 when I add them to the stage earlier. Even if I don't set x and y the sprite still moves on the stage when using just scaleX and scaleY. It does scale, but it also shoots off to the bottom if scale is less than 1, or just blinks and disappears for scale > 1. This is just so basic yet I can't work it out, sorry for the simple problem!

Link to comment
Share on other sites

your sprite has an x:0 y:0

the graphics inside the sprite start at 200,200

 

when you scale the container (mySprite) the relative position of it's contents will appear to shift.

 

from the code shown, that's the only thing I can imagine that is happening.

 

change your drawRect to 0,0, 30,30 and see what happens.

Link to comment
Share on other sites

  • 2 weeks later...

Carl, thanks again for your reply (and sorry about being unclear.)

 

The problem seemed to be that because the registration point of the sprite was in the top left corner, when the sprite is scaled, it also moves, especially when there is easing applied. The effect I was trying to get was an elipse growing from nothing to full size without actually moving. To get that effect, I had to move the registration point to the middle of the sprite, using code borrowed. With that done, the scaling looks like I wanted it to.

Thanks to all for all the great work done here.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...