IwGame Engine v0.32 Released – Data Bindings and Conditional Variables

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. You can find out more and download the SDK from our IwGame Engine page.

A lot of bugs (mostly minor) have been reported since the forum went live so we decided to release 0.32 now and push in-app purchasing to another future release (hopefully 0.33).

We finally got cOnnecticOns approved for BlackBerry PlayBook, its now on sale on BlackBerry App World. Version 2.0 also went live today for iOS on iTunes and for Android on the Android Market / Amazon. Not happy with Samsung however, the game has been knocked back on Bada 1 and 2 numerous times for minor issues that should be footnotes!

Ok, on with the changes, here is the list of changes for 0.32:

  • New XOML RemoveAllScenes action added – This will remove all scenes excluding the scene that is provided
  • Data bindings now added to XOML – You can now create a bindings list which pair properties up to variables. Changes made to those variables will bautomaticaly be applied to the object that they are bound to.
  • Actors and Scenes now support data bindings
  • Conditions variables now added to XOML – A condition variable allows you to string together some basic logic based on the value of other variables, these can then be attached to Actions to create conditional actions
  • Actions and Action groups now support conditional variables
  • IIwGameXomlResource now have parents
  • CIwGameString now supports encoding / decoding to / from hex
  • CIwGameSprite now has a RebuildTransformNow() method
  • CIwGameSprite now has an update method where the trabnsform will be rebuilt. This ensures that all transforms have been buuilt before rendering
  • CIwGameScene now has a PreDestroy() method which gets called when a request to destroy a scene is received
  • CIwGameActorImage now has a SetSrcRect() method
  • Added sound and music volume control to CIwGameAudio
  • CIwGameSound now accepts a paramater that allows you to specify volume, frequency and panning when playing a sound effect
  • BUG FIX: PNG lib fix for Visual Studio 2008
  • BUG FIX: Mac compile issues
  • BUG FIX: CIwGameSprite setScale() fixed
  • BUG FIX: Precision issues graphical glitches at lower resolutions
  • BUG FIX: Actor collilsion size now read corrctly from XOML
  • BUG FIX: CIwGameActorText text aligment now applie correctly
  • BUG FIX: When an actor or scene has a timeline attached, the first frame was not benig set before displaying the object
  • BUG FIX: CIwGameTextSprite hit test fixed
  • BUG FIX: CIwGameAds – VServ local now set correctly
  • BUG FIX: CIwGameScene – Initial camera transform is now built correctly
  • BUG FIX: CIwGameString::URLEncode now calculates correct buffer size
  • BUG FIX: CIwGameString::URLDecode now checks for the correct character
  • BUG FIX: Infinite loop removed from CIwGameXmlNode::GetAttribute()

The most exciting changes for us at least are the XOML data bindings and conditional variables / actions. They enable the creation of some very complex and ultra re-usable stuff. We are planning on starting a library of useful generic classes and XOML layout files that can be used as plug-ins to help create games and apps even quicker. Our first experiment with this is to create a set of XOML files and scene classes that handle ScoreLoop integration. If this is successful then we will release this as a plug-in library that you can simply drop into your own games and style with your own styles. Will blog about this in the near future.

XOML Data Binding

Data binding is the ability to map properties of objects to XOML variables. Changes to those variables will be immediately reflected in all properties of all objects that are bound. Lets take a look at a quick example:

We declare a global variable that holds a profile name:

    <Variable Name="ProfileName" Type="string" Value="None" />

Next we create a bindings set that contains a single property called “Text” that is bound to the “ProfileName” variable that we just defined:

    <Bindings Name="SC_ProfileBindings">
        <Binding Property="Text" Variable="ProfileName" />
    </Bindings>

We now attach our bindings list “SC_ProfileBindings” to a text actor:

    <ActorText Name="NameLabel" ......... Bindings="SC_ProfileBindings" />

Now if we change the ProfileName variable in XOML or in code, our NameLabel actor’s Text property will be automatically updated.

We opted to use independent binding lists (as opposed to in-line bindings as used in XAML / MXML) because they are re-usable, the same bindings list can be used across many objects. They are also much more readable as bindings are not intermingled with normal property values.

Note that if you also have a timeline animation that updates the same property then the timeline is given priority and the timeline will write over the binding value.

Binding lists can be attached to scenes and actors. The following properties can be bound:

CiwGameScene:

  • Position
  • Angle
  • Scale
  • Colour
  • Clipping
  • Timeline
  • Binding
  • Camera
  • Type
  • Active
  • Visible
  • AllowSuspend
  • AllowResume

CIwGameActor:

  • Position
  • Depth
  • Origin
  • Angle
  • Scale
  • Colour
  • Velocity
  • Angular Velocity
  • Timeline
  • Binding
  • Type
  • Active
  • Visible
  • Collidable
  • HitTest

CIwGameActorImage (in addition to those present in CIwGameActor):

  • Size
  • SrcRect
  • Image

CiwGameActorText (in addition to those present in CIwGameActor):

  • Text
  • Rect

Binding sets that are defined outside a scene will be assigned to the global resource manager, whilst bindings defined inside a scene will be assigned to the scenes resource manager.

Data bindings offer a way to create complex scenes and user interfaces without having to manually update the properties of the individual elements

Conditional Variables and Actions

XOML supports a new variable type called a condition variable. A condition variable is a variable that contains an expression that is defined by a list of variables, operators and values. Lets take a look at a quick example:

    <!--Create a bog standard int variable that contains the current level /-->
    <Variable Name="current_level" Type="int" Value="1" />

    <!--Create a condition variable that tests the current level is between 1 and 9 /-->
    <Variable Name="low_level_extras" Type="condition" Value="current_level GTE 1 AND current_level LT 10" />

We create an integer variable called current_level and assign it the value of 1. Next we create a new variable called “low_level_extras” that is of type “condition”. The most interesting part of our condition variables is the value, which is:

     current_level GTE 1 AND current_level LT 10

Unlike normal variables which contain constant values of some kind, condition variables contain dynamic expressions that are evaluated at run-time. The end result of a condition variable is always either true or false. The above expression in terms of C code would read like this:

     bool low_level_extras = (current_level >= 1 && current_level < 10);

Condition variables aren’t much use on their own and are usually used in conjunction with actions to provide conditional action functionality whereby an action or actions group will only be executed if a certain set of conditions are met. Lets take a look at a quick example:

    <Actions Name="NextScene">
       <Action Method="LoadXOML" Param1="MainScene.xml" />
       <Action Method="LoadXOML" Param1="LowLevelExtras.xml" Condition="low_level_extras" />
       <Action Method="KillScene" />
    </Actions>

The above actions group is called when we click a button to start a game. The actions group starts by loading the MainScene XOML file which creates the main game scene. Next the condition variable “low_level_extras” is checked to see if It is true, if current_level is between 1 and 9 then the variable will return true and the additional XOML file “LowLevelExtras” will be loaded. If however the current_level variable is less than 1 or greater than 9  then the additional XOML file will not be loaded.

This is just a very simple example showing how conditional actions can be used to re-use and extend XOML code.

And that’s it for this update. Thank you to all those who have downloaded cOnnecticOns on one platform or another and massive thanks to those who left us a review, you are awesome.

3 thoughts on “IwGame Engine v0.32 Released – Data Bindings and Conditional Variables

Leave a Reply