Thursday, April 29, 2010

Sprite Width and Scaling

Sprite children inherit the scaleX and scaleY properties of the parent sprite. But unfortunately if you ask the parent sprite for its width or height, it will return the current pixel dimensions.

If you want to get the true width of a Sprite so that when you add a child sprite to it the proportions match what you were expecting, then you can use this expression:
sprite.width / sprite.scaleX

The training queue system we are using for Pioneers Online is very similar to EVE's training system. We have a graphical bar representing skills waiting to be trained. Each skill has a variable time requirement, and we'd like this to be reflected in the graphical bar. In order to determine the appropriate width of a fill sprite, a proportion is calculated and is then used to set the width. I had forgotten that I scaled the empty bar in CS4, and this caused some headaches when I tried to add children to it.

No comments:

Post a Comment