lukasyno Posted June 6, 2013 Share Posted June 6, 2013 Hey, What is any simple way to calculate width/height of displayObjectContainer? Width/height property is only for Sprite... Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted June 6, 2013 Share Posted June 6, 2013 At this stage width and height are only available for sprites. It would be good to add it to displayObjectContainer too. The way it I imagine it would work is to loop through all children and get a max and min value to calculate width and height. I will put it on my todos Quote Link to comment Share on other sites More sharing options...
lukasyno Posted June 6, 2013 Author Share Posted June 6, 2013 Ok thx, so I will write some code.. DisplayObjectContainerUtil.computeWidth = function(target){ var w = 0; const n = target.children.length; for (var i = 0; i < n; ++i) { var child = target.getChildAt(i); if (child.anchor) w = Math.max(w, child.position.x + child.width * child.anchor.x * child.scale.x); else w = Math.max(w, child.position.x + child.width * child.scale.x); } return w;}DisplayObjectContainerUtil.computeHeight = function(target){ var h = 0; const n = target.children.length; for (var i = 0; i < n; ++i) { var child = target.getChildAt(i); if (child.anchor) h = Math.max(h, child.position.y + child.height * child.anchor.y * child.scale.y); else h = Math.max(h, child.position.y + child.height * child.scale.y); } return h;} Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted June 7, 2013 Share Posted June 7, 2013 Exactly my thinking! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.