0

in my game I have a solar system with many bodies, they're all the same class/movie clip and their size is determined by their mass. When assigned a target that target becomes a child of the body. The body moves towards the target and the target is removed when reached.

This approach is essential as it means waypoints can be set and the targets can orbit the solar system: because everything around the target is moving it also needs to move to keep relative motion otherwise you'd end up in the wrong place.

The problem is having the target a long distance away makes the body's bounding box huge and the body is shrunk down to fit the required dimensions. What I need is to make the target's position not affect the body's size but I can't find the required method/property and visible = false isn't doing the trick. If anybody has a solution that's be great.

Mat
  • 202,337
  • 40
  • 393
  • 406
Ashton
  • 7
  • 2
  • 2
    Short answer is, you can't, the .height and .width of a DisplayObject can't be set to smaller than its content, its children. Visually, you can use a mask to not display objects outside a bounding box, but the .width and .height will still be bigger than that box. One thing you can perhaps do, in line with the visible=false/true you have been trying, is to not addChild() the children until they are to be visible (so addChild() where you would set visible=true). You can read about masking at http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e0b.html – Lars Blåsjö Mar 24 '13 at 20:35
  • I tried that approach though it didn't work out: I need to update the size of the bodies as they combine and split though I did work out a simple solution I hadn't thought of before: Rather than setting the height and width I just set the scale and divided it or multiplied it by 50 where appropriate (how many pixels wide the graphic is). – Ashton Mar 24 '13 at 22:16
  • @LarsBlåsjö you are wrong. using includeInLayout = false; will cause the pointed object not to be included into parent size calculation. – Adrian Pirvulescu Mar 25 '13 at 16:19
  • @AdrianPirvulescu, includeInLayout is part of the Flex framework. The question mention nothing about Flex, was not tagged with Flex and did not sound like a project using Flex UIComponents. – Lars Blåsjö Mar 25 '13 at 20:19

1 Answers1

1

I believe includeInLayout may help you with this. visible=false will not display the object, but it's still used in the layout calculations. includeInLayout=false will remove the object from the layout calculations.

Bill Turner
  • 980
  • 1
  • 6
  • 23
  • 1
    Ah.. I discovered includeInLayout only applied to Flex, nevertheless the scale approach I mentioned above in the comments worked. – Ashton Mar 26 '13 at 16:09