Closed b005t3r closed 7 years ago
I gave setRequiresRedraw()
a quick look and I'm not sure if how it's implemented makes sense:
public function setRequiresRedraw():void
{
var parent:DisplayObject = _parent || _maskee;
var frameID:int = Starling.frameID;
_lastParentOrSelfChangeFrameID = frameID;
_hasVisibleArea = _alpha != 0.0 && _visible && _maskee == null && _scaleX != 0.0 && _scaleY != 0.0;
while (parent && parent._lastChildChangeFrameID != frameID)
{
parent._lastChildChangeFrameID = frameID;
parent = parent._parent || parent._maskee;
}
}
If an object requires to a redraw, it sets all ancestors to require a redraw as well, but I think it should do this for all descendants as well. With the current implementation they are going to be redrawn anyway, but this should be reflected in their internal state as well (reuiresRedraw
should return true
for such cases).
Starling marks the children as requiring a redraw only during rendering: otherwise, the logic of marking objects "dirty" would be very very expensive. Think of it: when you make a change to your root object, all of the children would need to be iterated over.
On rendering, on the other hand, we iterate through all objects anyway, so it's almost free to add that logic there.
This means that requiresRedraw
only indicates if the object or one of its children was changed, but does not take any parents into account. You could easily do that manually, though, by checking that property for all its parents, too.
Do you see what I mean?
Do you see what I mean?
Yeah, I've had this feeling it could hurt performance. It's still not ideal as it is currently, because checking if a given object will be redraw requires checking all of its ancestors, but I understand why it has to be this way.
Yeah, I did not really like it either, but there were some compromises I had to make in order to have the render cache not be too expensive in those cases where the display list changes.
I have this class:
Take a look at the
layout()
method. It's called on eachrender()
call andrequiresRedraw
for each child object is evaluated then.Now, if this display object is made visible and added to stage, everything works as expected -
requiresRedraw
isfalse
as it should be. BUT if this object is hidden and made visible on one of the subsequent frames (after it has been added to stage)requiresRedraw
returnsfalse
which is obviously not the expected behaviour, because these objects haven't been rendered yet at all.