-
Notifications
You must be signed in to change notification settings - Fork 30
Game Structure
There are a few objects types that make up the Platypus engine. What are they and how do they work? Glad you asked!
The Game object is the root object used when creating a game with the Platypus Engine. There should only be one game object. It is created by the SpringRoll PlatypusPlugin. The game object receives ticks from SpringRoll which it passes on to the scene. The game handles loading the scene object and transitioning between scenes. The first scene that the game will load as well as other global game settings are set in a configuration file (see Create Config JSON).
Scenes created from the Scene class are the next object in the hierarchy of the game. Scenes are best thought of as the mutually exclusive phases of the game (e.g. main menu, gameplay, etc.). There is only one scene active at a time and when a scene is not active, it is unloaded. A scene contains one or more layers and sends a ‘tick’ to each layer when it receives a ‘tick’ from the game. Scene definitions consist of a list of layer entities. For more on making a scene, check out Create A Scene.
Entities created from the Entity class make up the rest of the game structure. Entities are objects that contain a collection of components. The entity object does very little other than bind the components together and handle communication between them. The entity broadcasts any messages it receives to all of its components. Check out Create-An-Entity for more information.
Components make up the functionality of an entity. Components of an entity each handle discrete portions of functionality that make up the entity. Components communicate with each other by sending messages to the entity, which redistributes them.
Examples of components include Camera, SceneChanger, Mover, and RenderSprite. See the full listing of components in the Reference.
Layers are a category of entities that have a common component structure and are designed to contain other entities. Layers are contained in the Scene and act as the third layer in the hierarchy of the game. Layers contain an entity-container component to hold the entities added to the layer and one or more handler components that ‘handle’ processes such as rendering, collision, etc. The layer entity receives the tick from the scene and passes it to all of its components. Note that the components receive the tick in the order they are listed in the layer’s JSON definition. This is important because you may want certain processes (e.g. logic) to happen before others (e.g. rendering).
Handlers are components that regulate the functionality of an entity (e.g. making sure all the logic components are updated). When an entity is added to a layer, handlers receive notice of the new entity and check to see if it accepts certain messages that the handler controls. If so, the handler keeps a reference of the entity to communicate with it later. The order of the handlers in the layer entity definition determine the order in which they receive ticks.
An example of a handler is HandlerRender. Each time the HandlerRender component receives a tick from the layer, it sends a "handle-render" message to all of the renderable entities.
Other examples of handlers include the HandlerLogic and HandlerController components.