-
Notifications
You must be signed in to change notification settings - Fork 4
Components
Glue is a component based game engine. She contains multiple pre-made components you can combine to create your game object behave in the way you want to. We'll refer to those components as behaviours. Glue lets you easily create your own components to be able to specify specific behaviour.
In order to easily combine multiple behaviour components you can create a base component which will exhibit those behaviours. A base component can be created using the component module. You can pass along as many other components into the component module her constructor. Your component will incorporate all the other components (behaviours) you pass along. After that you can chain the add method and pass in an object which will represent your actual component.
The Glue game loop will keep on calling the draw and update methods on your base component as soon as you add her to the game. If some of the behaviours need to have update or draw methods called as well, you need to call these as well from your base component. You can see this call flow in the diagram below.
The behaviours will become accessible through the corresponding property names in you game component. If you for example use the droptarget behaviour, you can access it from within you base component by calling "this.droptarget".
In the next code example we create a component which is visible and draggable (these behaviours will be explained soon). As you can see we add the draw method, and make sure that the draw method of the visible behaviour will also be called.
glue.module.get(['glue/game', 'glue/component', 'glue/component/draggable'],
function (Game, Component, Draggable) {
var component = Component(Visible, Draggable).add({
draw: function (deltaT, context) {
this.visible.draw(deltaT, context);
}
});
Game.add(component);
}
);Currently Glue comes with the following built-in behaviours:
- Visible
- Animatable
- Clickable
- Hoverable
- Draggable
- Droptarget
