v5 Proposal, Return of the Stage
Chad Engler edited this page Jul 19, 2017
·
1 revision
- Child has no way to know whether parent was removed from the stage.
- The Destroy API is horrible, we just ask people to maintain it on their side, but we dont give any tools to determine the moment object leaves the stage, and user has to implement refcounting on his side.
- There is no way to differentiate container from the root element, this flag is maintained by user.
- Recursive calls of add/remove complicates the stacktrace, and problems in remove/destroy appear too often, we cannot isolate them, user will see the mess anyway.
Possible problems with naive implementations:
- If we simply pass 'added' and 'removed' messages recursively it will affect performance when we construct difficult scene.
- Any simple manipulation within the stage, like moving an element from one subtree to another will fire those events and possibly trigger some destroy sequence.
- If we just add special flag in "removeChild" that won't be good because people are having problems searching that flag in cocos2d engine, its not intuitive.
- Porting old code may be difficult if we force usage of the stage. We must ensure compatibility with old "container as root" approach.
- There might be cases with multiple stages inside each other. We have to resolve it somehow, stage needs to know about its
parentStage
.
- Put big sign for users DO NOT MODIFY
children
PROPERTY. - Mark all display objects with UniqueID
- Stage is Container that must store all its children in set by their ID. Elements store a link to the stage they were added.
- If subtree is added/removed to the stage, fire
added
/removed
event through whole subtree and re-assignstage
field for all elements. - Add
detachChild
method that does not fireremoved
but adds whole subtree to special stage'sdetached
set of elements, that can be removed on next frame, if user says so, or if special flag is enabled. Calling "addChild" on detached elements adds them back, withoutadded
signal/event. - Add/remove/detach works like in pixi-v4 when there is no Stage parent. Allow free modification of
children
in that case. - If the stage added inside another stage, it behaves as a single element: no recursive
added
/removed
. - All those manipulations must use BFS (queue) instead of recursion. It simplifies the debug process for users.