-
Notifications
You must be signed in to change notification settings - Fork 0
Create a Component
A group of components make up an Entity's functionality. Each Component serves a particular role for the entity. Together they make up the sum functionality of an entity by executing code when they receive messages and by sending messages of their own.
To begin we create a copy of the 'game/components/ec-template.js' and name it what we want to name our new component. This file is a template for creating a component and includes comments to guide us through the process of creating a component.
Once we've named our component we need to add it to the config.json file. We do that by adding it to the 'components' section of the config file and giving it an id. This is the id we'll use in our Entity definitions to indication which components we want.
Here's an example from the config.json file:
"components": [
{"id": "enable-ios-audio", "src": "components/enable-ios-audio.js"},
{"id": "handler-controller", "src": "components/handler-controller.js"},
{"id": "tiled-loader", "src": "components/tiled-loader.js"}
]
Once we've added it to the config file you can start editing the JavaScript file.
Here's a short list of the things you'll want to do to get started:
- Change the name of the component to match the id you gave it in the config file.
- For each entity event you want the component to handle, add it to the list of events.
- Make sure to handle closing down the component in a
destroymethod.
Platypus was developed by PBS KIDS and Gopherwood Studios. It is free to use (see licenses.txt), all assets in the example games are © Gopherwood Studios and/or © PBS KIDS.