When we are creating objects for a game, templates are useful. A template is a blueprint for a certain type of object, when we want such an object we can use the same template to always get an equal object. The template will specify which modules that the object use and how the object’s attributes will be configured. Finally, a template can also define scripts, called triggers, linked to local events. When the local event occurs for an object of this type, the trigger is invoked.
Templates in Ophelia ware defined in XML files.
A template looks like this:

<!-- Always start with the Template tag-->
	<!-- Give the template a name -->
	<!-- Which components does this object use? -->
	<!-- Which default attribute values does the object have? -->
	<!-- Which scripts will trigger on which events? -->

To finish defining this object, we also need to define the scripts that make up the template’s triggers. This will be done in JavaScript and can be written anywhere in the project. It looks like this:

Ophelia.defineTrigger('onPlayerCollide', function(data){
	var player = data.collidingObject;
	// Code that is invoked when the player collides

Ophelia.defineTrigger('onPlayerUpdate', function(data){
	var player = data.updatedObject;
	// Code that is invoked when the game updates
Be Sociable, Share!

Published by

Albert Öhrling

Studies computer science in Skellefteå, at Lulea University of Technology.

Leave a Reply

Your email address will not be published. Required fields are marked *