IwGame Engine v0.3 Released – The 36 hour game

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.

Well, Dan said a few weeks ago that “it’s only until you eat your own dog food that you know you have to improve the taste of it”. I thought about this and decided that we really needed to create a game using the engine to show its various features in action. So with this, I began work on a game (currently unnamed), but decided that the game would take a few weeks to finish off, so moved over to producing a completely new game from scratch but with a simpler design. The end result was a game that was created in less than 36 man hours, including art production, coding, design and scripts (I was aiming for 24 hours but I came across a a few nasty bugs that took a fair bit of time to fix). In addition,. I underestimated how difficult it would be to put levels together without an actual editor. I will very likely build an actual editor into the cOnnectiCons game itself to allow players to create their own levels. So the game ended up with 20 levels, with an additional 20+ levels coming later.

You can take a quick look at cOnnecticOns at http://www.youtube.com/watch?v=sVa8TWYQEsQ and here are a few screen shots of our 36 hour game cOnnecticOns:

Connecticons screen shot
Connecticons screen shot
Connecticons screen shot
Connecticons screen shotConnecticons screen shot
Connecticons screen shot
Connecticons screen shot

We have already started submitting the game to app stores, so when we release the source “Don’t go getting any ideas lol”. The source will be provided as a learning exercise, and not for someone else to make a quick buck off.

Ok, now that’s out the way, lets take a brief look at the changed that have arrived in IwGame v0.3:

  • Support added for particle based actors via CIwGameActorParticle and CIwGameActorParticles as well as XOML via ActorParticles and Particle tags. Particles can be defined individually or in batches using random parameters. Particles have position, linear velocity, angular velocity, scale velocity, colour velocity, depth velocity, velocity damping, lifespan and repeat
  • Support for Marmalade fonts has been added via CIwGameFont wrapper and a new XOML Font tag
  • All rendering now uses IwGx instead of Iw2D. This offers more control over rendering as well as makes the code more portable / versatile in the future
  • All internal rendering upgraded to sub pixel coordinates offering MUCH smoother rendernig
  • New 2D rendering class added CIwGameRender2d. This cklass allows batch rendering of primitives and rendering of text CIwGxFontPreparedData prepared text
  • New very powerful template system added to XOML. The template system allows you to create a complex piece of XOML using paramaters that can be passed in when the template is instantiated. Templates can also be instantiated from code using CIwGameTemplate::Instantiate()
  • CIwGame::addScene() can now auto bring a scene to the front of scene stack
  • New global actions added to XOML – Launch, setBGColour, SetCurrentScene and BringtSceneToFront
  • Actors and sprites now have a depth property allowing you to add 3D depth to them
  • Actors and sprites now have an origin attribute
  • Support added for sprites and actors for none uniform scaling
  • Support added for linked actors. A linked actor will utilise the transform, colour and visibility of the actor it is linked to. In XOML, you can use the new LinkedTo tag to set linkage or the more natural and readable method of defining actors within actor tags. This system allows complex multi-patr actors to be created and animated
  • Actors now support OnCreate and OnDestroy events in code and in XOML
  • Scenes now support OnCreate, OnDestroy OnGainedFocus and OnLostFocus events in code and in XOML
  • New text based actor and sprite types added CIwGameActorText and CIwGameTextSprite.
  • Animation system now supports linear, quadratic, cubic and quartic on / out easing in code and in XOML. In addition value interpolation can be enabled / disabled
  • Animations now support absolute and delta values
  • Animation timelines now support OnStart, OnEnd and OnRepeat events in code and in XOML
  • CIwGameAudio::PlayMusic now supports repetition with additional parameter in XOML
  • New CIwGameSlotArray class added for efficient resizable arrays
  • Actor Box2D collision system was broken and inefficient. The system has been completely reworked and now uses the new more efficient CIwGameSlotArray
  • CIwGameBox2dBody now has new awake and active methods
  • CIwGameCamera now supports velocity, damping and touch panning. Touch panning will pan the camera to follow the users finger
  • More than one scene can now receive input events using the new AllowFocus functionality in code and in XOML
  • New findClosestActor and findFurthestActor methods added to CIwGameScene
  • CIwGameBitmapSprite now supports colour per vertex
  • CIwGameSpriteManager supports enabling / disabling of batching and a new centre of projection property for depth used by depth sprites
  • CIwGameInput reworked to better support multi-touch
  • PlayTimeline, StopTimeline and SetTimeline now supports a second parameter which points to the scene or actor that the timeline change should be made to
  • Actors can now be marked for hit testing in XOML
  • Image files can now be loaded directly from XOML without the need for Marmalade resources files
  • CIwGameScene and CIwGameActor based objects are now marked as destroyed when they are removed so they cannot be found in a scene or actor search
  • CIwGameXmlNode now supports cloning
  • Bug Fix: Actors now take into account their visibility when being hit tested
  • Bug Fix: CIwGameActor::setCollidable no works
  • Bug Fix: StartTimeline action now restarts a stopped timline properly
  • Bug Fix: Clipping rect is now transform by the scenes transform (will not clip correctly against rotated scenes however)
  • Bug Fix: XML parser fixes
  • Bug Fix: CIwGame game scene switch scene bug fixes
  • Bug Fix: CIwGameAds::ErrorFromResponse fix that were causing some valid ads to be in error
  • Bug Fix: CIwGameAnim fixes
  • Bug Fix: Polygon based Box2D bodies now fixed
  • Bug Fix: Sprite rendering transform fixed
  • Bug Fix: CIwGameBitmapSprite with no loaded image no longer crash
  • Bug Fix: CiwGameString crashes fixed (were causing rare problems with XML system)
  • Bug Fix: Fixed issue with CIwGameXmlAttribute::GetValueAsColour not checking for correct parameter count
  • Bug Fix: On device scene shut down camera deletion fixed

Ok, that’s a shed load of changes, but I can assure you that they are all for the better. IwGame is now a professional grade and fairly stable engine that can be used to create games in as little as 36 hours!

Lets take a look at some of the new additions in more detail.

Templates

I want to start with my utmost favourite change to 0.3 which is templates. I am so in love with templates that I feel like I could almost marry one! They saved me so much time when developing cOnnecticOns. Templates allow you to create large sections of XOML as templates then instantiate those large
pieces of XOML somewhere else using custom parameters that you pass to the template when you instantiate it. Lets take a quick look at a super simple example:

<Template Name="ActorTemplate">
        <InertActor Name="Explosion$name$" Image="$image" Position="$pos$" Scale="$scale$" Depth="$depth$" Layer="1" AngularVelocity="0" />
</Template>

Here we define a template called ActorTemplate that contains a basic InertActor definition. You may notice some strange markers in there surrounded by double dollars signs ($name$, $image$,$pos$, $scale$ and $depth$).

Now when we instantiate this template somewhere we would use:

<FromTemplate Template=”ActorTemplate” name=”actor1″ scale=”1.0″ pos=”300, 150″ depth=”1.0″ image=”sprites1″ />

The above XOML command will instantiate whatever is in the ActorTemplate template passing all of its parameters, replacing the double dollar definitions inside the template (Hmm, sounds very much like calling a function? Which I guess in some ways it is)

Templates can be as massive and as complicated as you like, allowing you to design and instantiate some very complex objects with very few lines of XOML.

Rendering Engine Upgrade

Up until version 0.29 of the IwGame Engine we used Marmalade’s Iw2D engine as the rendering core. As of v0.30 we have switched to Marmalade’s IwGx rendering system as it offers much more versatility as well as brings the engine into the realms of 3D rendering, which is where we will eventually be steering the engine.

To facilitate this change over and to keep the game engine code nice and readable, all rendering has been abstracted away into a nice simple class called CIwGameRender2d. CiwGameRender2d is and will in future be the centre point for all rendering that takes place within IwGame.

At the moment CiwGameRender2d offers:

  • Batch and none batch sprite rendering of quad based polygons
  • Rendering of prepared text from the Marmalade IwGxFont system

In the near future we will be adding support for various other types of primitives, 3d models and hopefully our own custom shaders etc..

Lastly, all rendering now uses sub-pixel accuracy which looks much much smoother.

Text and Fonts

IwGame now supports definition of Marmalade fonts and custom rendering of those fonts using a new text based sprite and actor. Text based sprites and actors are treat just like any other sprite or actor objects, so they can be spun, scaled, linked, colour changed etc.. Unlike generic actors text based actors can be instantiated without deriving your own class from CIwGameActorText

3D Sprites / Actors

Another one of my favourite additions to 0.3 is 3D sprites. All sprites and actors can now have a depth value (think iof this as a z value) that allows you to project sprites into 3D.  This system is great for create parallaxing effects etc..

Oh and sprites / actors also get an adjustable origin and none uniform scaling

Linked Actors

Actors can be created within other actors to form a parent / child relationship. Inner actors will be linked back to their containing actor forcing them to be transformed by their parent actors. This system allows you to create a very powerful intuitive multi-part actor system complete with animations per actor part. Note that all positions, depths etc will be relative to the container actor, so for example, if the parent actor has a Depth value of 1.0f and the child actor has a Depth value of 1.0f then the child’s effective Depth will be 2.0f. Here’s an example showing parent / child actors:

<InertActor Name="Level1" Style="LevelButtonStyle" Position="0, 0" OnBeginTouch="BeginTouch11" OnTapped="StartLevel1">
    <ActorText Name="Record1" Style="LevelButtonTextStyle" Colour="255, 80, 80, 255" Position="0, 0" Text="0" Depth="0" />
    <ActorText Style="LevelButtonTextStyle" Position="0, 60" Text="Round 1" Depth="0" />
    <InertActor Name="LevelComplete1" Size="74, 67" Image="sprites2" SrcRect="582, 423, 148,134" Position="60, -20" HitTest="false" Depth="0" Timeline="tick_scale_anim" />
</InertActor>

In the above XOML the parent actor level1 contains three children actors that will all follow theLevel1 actors visual transform.

Particle System Actors

This actor is special in that it is optimised for creating, displaying and updating a complete system of sprites (kind of like its own sprite manager). The advantage of this actor is that it does not have to deal with each particle as a separate actor object. The CIwGameActorParticles actor supports both manual and auto generation of particles. Auto generation can be controlled using a number of a control parameters.

Particles have a number of properties that can be adjusted:

  • Visual
  • Position
  • Velocity
  • Velocity Damping
  • Gravity
  • Scale
  • Scale Velocity
  • Scale Velocity Damping
  • Angle
  • Angle Velocity
  • Angle Velocity Damping
  • Colour
  • Colour Velocity
  • Colour Velocity Damping
  • Depth
  • Depth Velocity
  • Depth Velocity Damping
  • Active state
  • Visible state
  • Lifespan – Duration of particle in seconds
  • SpawnDelay – The amount of time to wait before spawning for the first time
  • Lives – Number of times the particle will re-spawn (-1 for infinite)

The particle actor system allows auto generation of particles within certain limits as well as manual generation. Patricles can be defined and placed both in code and in XOML.

Animation Frame Easing

Animations now support in and out easing on a per frame basis using the “Ease” attribute of the frame tag or in code. Valid values of easing include:

  • linear – No easing
  • quadin / quadout – Quardatic in / out easing
  • cubicin / cubicout – Cubic in / out easing
  • quarticin / quarticout – Quartic in / out easing

Time lines now in the Events System

Its now possible to attach actions to timeline events such as OnStatr, OnEnd and OnRepeat. So for example, each time an animation repeats you could play a sound effect or maybe when an animation finishes yu kill destroy the actor or start a particle system off going etc..

Animations now support delta / absolute coordinates

Every animation can now be specified as absolute or delta. An absolute animation will write its interpolated frame values directly into the target objects properties (such as position), whilst a delta animation will update the current target properties. So for example, a delta animation for position would adjust the position by dx, dy, where dx and dy is the current interpolated frame value.

Automatic Touch Panning for Cameras

Cameras now have X and Y axis touch panning. When a camera is touch pan enabled it will track the users finger drag on screen to determine a velocity to move the camera by. Touch panning can be enabled on the X an Y axis independently.

Other cool changes

Multi-focus scenes – More than one scene can now receive input events
Local images can now be loaded from XOML

There are many other changes but I don’t really have the time to go through them all. There’s also a mound of bug fixes that weer found during development of cOnnecticOns.

We will be releasing the full source to cOnnecticOns later this week along with an additional 10-20 levels.