Skip to content
This repository was archived by the owner on Apr 15, 2022. It is now read-only.

Create a Component

Derek Detweiler edited this page Sep 23, 2015 · 6 revisions

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 "examples/component-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 configuration. We do that by simply including the component's JavaScript file in springroll.json in the "main" array of files.

Here's an example of three custom components added to the springroll.json file:

"main": [
	"src/components/AIConductor.js",
	"src/components/AIPilot.js",
	"src/components/IntroBrain.js",
	"src/main.css",
	"src/main.js"
]

Once added, 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 name 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 starting up the component in the constructor and closing down the component in a destroy method.

Clone this wiki locally