开发者

Do you know how to force a Sprite to position children in reference to 0,0?

I'm trying to add some scroll bars to a Sprite using ScrollRect. The Sprite starts empty and when I add something at 500, 500, it sho开发者_如何学编程uld scroll, as it is outside the viewport. Unfortunately, adding a 10x10 Sprite at 500, 500, doesn't make my Sprite change its size to 510, 510, but to 10, 10 ::- (.

We all know that DisplayObjectContainers resize according to what's put in them. But I didn't know up until today that if you put something at 500, 500, the Sprite / DObjContainer will NOT resize from 0, 0 to 500, 500, but simply jump directly at 500, 500. Annoying, as I cannot put Scrollbars on something whose content fluctuates so. I need 0, 0 to remain 0, 0 and if something is placed at 500, 500, the sprite's height should increase with 500 + that something's height.

Ideas? Insight?

Thank you in advance ::- D, Scrollmasters ::- D.


This will not change the height/width of the Sprite so I'm not sure it will help you. But in case you control the code that does the scrolling, you could calculate the size of your object (considering its origin is always 0,0) by getting it bounds and adding x + width and y + height. Something like this.

var rect:Rectangle = sp.getBounds(sp);
var w:Number = Math.abs(rect.x) + rect.width;
var h:Number = Math.abs(rect.y) + rect.height;

I'm using Math.abs in case you add children at negative offsets, but from your description that's not the case, so you could avoid that step.


quick fix, maybe not too elegant... add a Shape in your Sprite with a fixed height of 500 and set the alpha to 0 or use it for a nice colored background :)


I made it this way:

Container (sprite)
    scrollbars
    content (sprite with scrollrect)

In content sprite, draw a rectangle to give it full size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜