Show objects and display list
"Show Object", the exact meaning of "Show Objects" is an object that can be displayed on the stage. Objects that can be displayed include graphics, text, videos, pictures, etc. that can be directly seen, as well as display object containers that cannot be seen but are real.
In Egret, visual graphics are all composed of display objects and display objects containers.
If we want to express the scene in the picture above, how should we describe it in a tree way?
Display object hierarchy structure
In Egret, display objects are divided into two categories: one is a display object container that can include other display objects, referred to as "containers". Another type is a simple display object, which cannot include other display objects except itself, and is referred to as "non-container object".
In actual operations, we can regard such a structure as a tree structure, the container can be understood as a branch, and non-container objects can be understood as leaves.
In this tree-like structure, the top one is the "stage". Corresponding to the program, we can see a stage object. The stage is the most fundamental display container in the Egret display architecture. Each Egret application has and only one stage object. The stage is the root node of this display tree structure.
On the stage, we also have a main container. This container is the container created by the document class. Each Egret will have a document class, which must be a display object container.
In this scene, we include a scene background, and the background consists of a background image and a big tree. The other two elements are composed of characters and a grassland.
Show list
The tree-shaped display object structure diagram we see above is actually Egret's "display list".
It is very convenient to use display lists to manage container and non-container objects. When a display object is in the display list, we can see the object in the screen. When we remove the display object from the display list, the object disappears from the screen.
There is a display list maintained within Egret. Developers do not need to care about how the list runs. You only need to perform corresponding operations on your display object.
Show object types
During the architectural design process, Egret strictly encapsulates all objects around the concept of displaying lists. In Egret, all display objects are inherited from DisplayObject class. DisplayObject class is the "display object" we described earlier. In Egret, all "containers" are inherited from DisplayObjectContainer .
In order to manage the display list uniformly, all display objects are unified in the DisplayObject class. All display objects are inherited from DisplayObject, and DisplayObject is inherited from EventDispatcher. That is to say, all display objects can send events.
DisplayObjectContainer displays that the parent class of the object container is also DisplayObject.
In actual operation, we simplify the concept again, which can be summarized into two rules:
Classes directly inherited from DisplayObject are all non-containers. Classes inherited from DisplayObjectContainer are all containers.