Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.85k stars 819 forks source link

DisplayObject's size with clipRect vs mask - Starling 2.0 #846

Closed timoisalive closed 8 years ago

timoisalive commented 8 years ago

Previously when using clipRect, the display object's size would update according to the clipRect. Instead of clipRect one should use a mask inStarling 2.0, but unfortunately the display object size is not affected by the mask. Is this on purpose or is this a bug...?

If it's on purpose, how should I get the "masked size" of an object, if the mask is nested somewhere deep in the display object's children...?

PrimaryFeather commented 8 years ago

Yes, that's one feature that was lost with the change of making clipRect just an internal optimization of the mask feature. Sorry!

So you have to do this manually. The best approach depends on your actual problem, of course. Perhaps there's a simpler solution in your case, but one way to do it is to recursively search for a masked display object and use the getBounds method on the mask to find out its bounds in another coordinate system. You can then use the RectangleUtil to intersect the actual object bounds with the mask bounds. (The mask must be part of the display tree (have a parent) for this to work.)

I know that this is more difficult then before, but the old behavior had to be changed in that respect. Let me know if you need any more help!

timoisalive commented 8 years ago

Ok, no worries, and thanks for the workaround tip! :)

PrimaryFeather commented 8 years ago

You're welcome, and thanks for your understanding! :smile: