IwGame Engine – Using Templates Tutorial

New here? What’s IwGame? IwGame is an open source free to use cross platform game engine for iPhone, iPad, Android, Bada, Playbook, Symbian, Windows Mobile, LG-TV, Windows and Mac, built on top of the Marmalade SDK.

A forum poster asked a question recently that made me realise that XOML Templates can quite easily be overlooked as a means for creating re-usable actors and such, so I thought to help make Templates more visible that I would create a very quick tutorial showing how to use them.

To begin with, lets take a look at what a template actually is and does. A template is a XOML tag that allows you to define generic XOML that is not instantiated immediately, yuo can think of a Template as a blue print for something that you will later instantiate into your game or app world. A template also takes any number of parameters that can be passed when you instantiate the template.

When creating items inside a Template, template parameters are defined using a template parameter name that is enclosed inside double dollar signs ($$), for example $position$. When you later instantiate the items within the template the parameters within the template will be replaced by values that are passed to the template.

Lets take a quick look at creating an actor / child actor with a template

    <Template Name="TankTemp">
        <TankActor Name="$name$" Style="TankActorStyle" Position="$pos$″ >
            <TankActor Name="$name$_sel" Style="TankActorSelectedStyle" Position="0, 0″ />

Here we create a template called TankTemp that defined an actor with a name of $name$ and a position of $pos$. Note that because these two parameters are enclosed in $$ they are classed as template parameters.

Now to instantiate this elements within this template in XOML we use the following:

        <FromTemplate Template="TankTemp" name="Tank" pos="310, -120" />

The above code will instantiate the following code:

    <TankActor Name="Tank" Style="TankActorStyle" Position="310, -120″ >
        <TankActor Name="Tank_sel" Style="TankActorSelectedStyle" Position="0, 0″ />

To instantiate a template from C++, we firstly need to find the template, build the parameters then instantiate the template passing in the parameters:

// Find the tank template
CIwGameTemplate* temp = (CIwGameTemplate*)scene->getResourceManager()->findResource("TankTemp", "template");
if (temp != NULL)
	// Create a set of XML attributes that will replace the template parameters
	CIwGameXmlNode* replacements = new CIwGameXmlNode();
	replacements->Managed = false;
	CIwGameXmlAttribute* attrib;

	// Set name template parameter
	attrib = new CIwGameXmlAttribute();
	attrib->Managed = false;

	// Set position template parameter
	attrib = new CIwGameXmlAttribute();
	attrib->Managed = false;
	attrib->setValue("310, -120");

	// Instantiate the Tank template
	temp->Instantiate(scene, replacements);

	// Clean up replacement attributes
	delete replacements;

AppEasy – Coming Soon – Beta Testers Wanted

I would like to mention a new service that we plan to roll out very soon called AppEasy. AppEasy is a game and app development system that enables anyone to develop cross platform games and apps for iOS, Android (soon Samsung Bada and BlackBerry PlayBook) without the need for C++, Objective-C, Java or compilers / other SDK’s etc.. The AppEasy system involves using XOML and Lua (other script languages to be added soon) to create apps. To build an app you simply drag and drop all of your assets onto a web app, set some parameters for your game or app, such as icons, app name etc.. then hit deploy. Builds for each platform are then created that you can submit to the app stores. You can also hit a debug button to test your app locally. The system will be Windows only to begin with as we cannot gain elevated security permissions on Mac from Silverlight 5, we are still looking into options for Mac and Linux. If you are interested in beta testing this new service then get in touch with us at http://www.pocketeers.co.uk/?page_id=8. We are only offering a limited number of spots initially, so grab them whilst they are available. Now for a quick poll:

Is AppEasy something you are interested in?

View Results

Loading ... Loading ...

Whilst the pricing structure is not yet final, AppEasy will be priced competitively, although a free version will most likely be made available that embeds an Ad into deployed apps that generate revenue for us on start up. Money made from AppEasy will be spent on improving IwGame / AppEasy and other cool developer tool projects (such as the IwGame editor) that we have in the works.

If there is anything that you strongly agree / disagree with then please feel free to comment.