Render Helpers and Templates

This page explains how Gamma uses gma.renderHelper to provide the link between Gamma entities and the rendering engine.

Everything that is rendered in Gamma is found inside the entities or levelExtras property of the current level. The content of the entities list doesn’t matter, as long as each entity has a helper property that is an instance of gma.renderHelper, and that the render helper has a template property set to a descendant of gma.baseTemplate. These render helpers are used to provide the visual representation to the scene helper.

Note

See Appearance for more information on templates

As a part of processing a level, in the process_entities method, the levelParser will go through all the entities in the level and use prepareEntity to give them each a gma.renderHelper.

These render helper objects are responsible for ensuring that the visual representation of the entity it belongs to has the correct size and position and is added to the current sceneHelper. The render helper also maintains a cache of the object specifying this representation.

Registering with the SceneHelper

As a part of loading a level, loadLevel will go through the entities list on the current level and ask the sceneHelper to add each entity’s helper object.

This will cause the gma.sceneHelper to call the render helper’s addTo method with a container that it can add the visual representation to.

Maintaining size and position

As part of the Game Loop, the manager’s sceneHelper is asked to render the scene using it’s render method. This method will first update all the objects specific to the rendering engine using setRenderedLocations and then use ask the rendering engine to render everything.

The setRenderedLocations method will go through each entity on the current level and call setLocation on each entity’s render helper. This method will get the object that represents the entity and make sure it accurately represents the size and position of the entity.

Note

The setRenderedLocations method is also responsible for ensuring anything registered as being attached to something else is moved when that entity is moved.

Providing a cache

To get the rendering specific object from a render helper, we call it’s getRenderedObj method. This method will look for an _instance attribute on the render helper. If it does not have one, then it will ask it’s template (one is added as part of prepareEntity) to give it an instance to work with by calling it’s getInstance method.

Note

You can override the template on the render helper just by setting it’s _instance property.

Fork me on GitHub