0
votes

I have an object manipulation function that(right now) manipulates the scale of the objects inside of an array to give real-time size changes in relation with each other.

What I would like to know is if there's a way to change an object's width/height(to fit the screen size since it's a mobile app) and then reset the scale so that the new width/height has a scaleX/scaleY value of 1.

1
One possible idea is to have the objects in some container object and to scale the container. Then the objects will retain the scaleX/Y value of 1.JKillian
I'd rather avoid creating unnecessary container objects, but if there's no way to reset an object scale to a new width/height it is the best solution. Thanks.user3071888
Redraw the object, especially if it's just a primitive (a rectangle, etc).Vesper

1 Answers

1
votes

The width/height are properties that directly influence the scale of a DisplayObject. You cannot resize it without affecting the scale.

You can however:

  • Draw the image as bitmap
  • Redraw it if it's a primitive
  • Put it in a holder

A little about every solution:

Drawing a DisplayObject (or any IBitmapDrawable) is done through creating a BitmapData and using a draw() call. The up-side is that it will be a bitmap and thus save some rendering time. The downside is that if it's a large image it will take memory (can be critical for mobile) and it won't have interactivity/animation unless you make a script that would read the animation.

If you're drawing the element though the Graphics class's API, you might just make something like a resize() method that you would call on window resize/flip-orientation. Just utilise the clear() method of the Graphics object and redraw the whole thing.

Lastly, probably your best pick. Resize your object. Make a new Sprite (I choose Sprite because it's interactive and you probably want that) and add the resized object to that newly made sprite while the Sprite is just added to the display list like you added the resized object before. If it's hard to understand, here's some code:

myResizeableObject.width = newWidth;
myResizeableObject.scaleY = newScaleY;

var holderSprite:Sprite = new Sprite();
myResizeableObject.parent.addChild(holderSprite); // if you don't have a specific place to add the myResizeableObject, don't use myResizeableObject.parent - it's ugly
holderSprite.addChild(myResizeableObject);

Hope that helps you!