Jump to content

DisplayObjectContainer size


lukasyno
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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;}
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...