As I’ve found recently, setting width/height properties on a Sprite only forces the Sprite to fit the given dimensions by scaling the actual size, which is calculated by Flash based on the rendered content.
This leaves me confused. If I have a custom Sprite subclass which draws using Graphics, how can I do layout before an initial render – the size will be zero until it is first drawn?
For a more complex issue, let’s say I have a 2D game world with objects spread over a wide area with world coordinates from (0,0) to (5000,5000), where each object has a size of maybe up to 100×100.
I want to have a Flash component which is the “game window”, and has a fixed size like 400×300, rendering part of the game world. So how do I force the game window size to 400×300 pixels? I can draw a 400×300 rectangle to get the size correct but then if I draw any objects which are partly in-view, they can screw this up.
Is the right approach to provide a custom setSize(w,h) method which is used rather than width & height setters? But even so, is there no way to make a Sprite force to the size I want? Do you really have to catch it every render and re-scale it?
If I understand correctly, your game world is a child object of your window, and its size is always 5000×5000, but you need
widthandheightof the window to refer only to the window itself? Use a mask, as the other comment suggests, then override thewidthandheightgetters and setters: