Talk about `renderChildren` again.
See original GitHub issueOne year ago , I created a PR https://github.com/pixijs/pixi.js/pull/3108/ .
I want to add the standalone methods about rendering & updating children.
The reason is that user could override them for controlling which sprite/how render the sprite
by themself .
example:
There is a DisplayObject-Tree:
containerA |_____ spriteA |_____ spriteB |_____ spriteC |_____ subContainerA |_____ … some other sprites else …
Sometimes , I want to decide that render which sprite/how render the sprite
by myself, like this :
if ( condition1 ) {
spriteA.renderWebGL(renderer);
spriteB.renderWebGL(renderer);
} else if ( condition2 ) {
spriteB.renderWebGL(renderer);
spriteC.renderWebGL(renderer);
spriteA.renderWebGL(renderer);
} else if ( condition3 ) {
spriteC.renderWebGL(renderer);
subContainerA.renderWebGL(renderer);
} else {
subContainerA.renderWebGL(renderer);
}
The logic above can’t be solved by children.sort
.
If we extract the method about rendering children , user could override the renderChildrenWebGL
& renderChildrenCanvas
, it’s easy.
there is another use case for custom remove
:
container.renderChildrenWebGL = function(renderer) {
// In one game loop , the render is the last thing about an entity normally.
// So we could remove the entity in render function.
var i = 0,
len = this.children.length;
while (i < len) {
var child = this.children[i];
if (child._toRemove) {
len--;
this.removeChildAt(i, child);
continue;
}
child.renderWebGL(renderer);
i++;
}
};
If no standalone renderChildren
, users have to override renderWebGL , renderCanvas, renderAdvancedWebGL
, it’s complex , in especial renderAdvancedWebGL
.
And if the logic in Container.prototype.renderWebGL/renderAdvancedWebGL
changed , users have to re-override them again.
But the logic of renderChildrenWebGL
& renderChildrenCanvas
is very clear , and they won’t be
changed.
One year ago , @englercj refused my PR , the reason is performance
.
In the past year , I’ve tested many games (more than 20 games , and more than 100 test-cases) , I found this PR is not the hotspot of performance, even never affected performance.
(BTW, I found the updateTransformChildren
is needless , I and my friends never used it).
In the real game , we could use many sprites , but the count of container is not big at the same time( in one game tick), so the 1 function-call won’t take the performance down.
So I hope you could think the PR again, please, thank you.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
@finscn im working on a way to override pixi container methods in a plugin, and your input is significant. Lets close this one, I’ll address it later 😃
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.