IwGame Engine Update – v0.230

Well its been an interesting day to say that its a Sunday, some good news and some bad new . The good news is that I managed to sneak some time in today to add a few updates to IwGame. The bad news is that some robbing (insert lots of non-religious type words here) has skimmed my card and robbed my bank account! (Can’t these people just get jobs like the rest of us!). Anyways, anger vented, now to get back on topic. We have just updated the IwGame game engine to v0.230. If you don’t know what IwGame is then in short it is a cross platform game engine for smart phones and tablets based upon the awesome Marmalade SDK. Here are the new features:

  • Added CIwGameImage::CreatePNG(int& size) to CIwGameImage to allow the creation of memory based PNG files
  • Added pngilb and zlib dependents
  • Added helper support to CIwGameInput for detecting touched, tapped events, delta change and back / menu buttons
  • Added CIwGameSprite::HitTest(int x, int y) which basically tests to see if a screen point is inside a sprite (takes into account scaling and rotation)
  • Added CIwGameAudio, CIwGameSound and CIwGameSoundCollection classed to support playback of sound effects and music
  • Added visual layers to sprites and actor system allowing sprites / actors to be depth layered
  • Added support for clipping in CIwGameScene. The scene can now be clipped to a rectangular area of virtual canvas

And here are the general changes / bug fixes:

  • Changed CIwGameFile::Open(const char* path, const char* mode, bool blocking), we now use mode instead of read / write flag
  • Added new CIwGameFile::Seek(int offset, s3eFileSeekOrigin origin) method
  • Replaced CIwGameHttpPostData::AddHeader() with CIwGameHttpPostData::SetHeader() to allow replacement of http headers
  • Added ClearRequests() and CancelRequests() to CIwGameHttpManager() allowing us to clear the request queue and cancel any in progress http requests
  • Removed two bugs from CIwGameInput, one that was stopping button / key presses and another that was preventing keyboard update if touch screen wasn’t present (doh!)
  • Added helper support to CIwGameInput for detecting touched, tapped events, delta change and back / menu buttons
  • Fixed CIwGameScene::removeActor(CIwGameActor* actor) bug (could not remove unnamed actors)
  • Fixed CwGameScene::removeActor(unsigned int name_hash) (would not deallocate pooled actors for re-use)
  • Fixed sprites initial state as invisible bug in CiwGameSprite
  • Moved Width and Height from CIwGameBitmapSprite to CIwGameprite, makes sense that all sprites would need to have a size
  • IwGame has been made into its own standalone project
  • The IwGame Testbed has now been moved to the TestBed folder

Important note, IwGame now exists as a separate project from the test bed. You now have to add IwGame to your project by adding IwGame to the subprojects section of your MKB file. The test bed is also a separate project and is located in the IwGame sub folder named TestBed. Lets take a quick look at some of the changes

Sprite Depth Layers

Its now possible to layer sprites in a sprite manager. The feature is automatic, all you have to do is set the layer of the sprite using setLayer(int layer_number). To set the number of depth layers available to the sprite manager you pass the layer count into the sprite managers Init() method. The default is set to 10 layers. As a scene contains a sprite manager to handle its contained visuals, you can also specify the number of depth layers when you initialise a scene: int Init(int max_collidables = 128, int max_layers = 10); Again, the default is 10 layers. Note that sprites on higher layers will be drawn on top of sprites on lower layers.

Creating PNG’s

You can now create an in-memory PNG file from a  CIwGameImage using CIwGameImage::CreatePNG(): uint8* png_data = image->CreatePNG(png_size); The method currently only supports images in RGB_565 and RGB_888 format. more formats will be added when I implement a new pixel conversion helper class.

CIwGameInput Expansion

I decided to pan CIwGameInput out a little adding new methods to do common tasks such as:

  • bool hasTapped() – Returns true if user tapped the screen
  • bool isTouching() – Returns true if user is currently touching the screen
  • CIwVec2 getTouchedPos() – Returns the position at which the user is touching the screen
  • CIwVec2 getDragDelta() – Returns the number of pixels the user has moved their finger / stylus since the last frame
  • bool isBackPressed() – Returns true if the back button was pressed (nice for Android)
  • bool isMenuPressed() – Returns true if the menu button was pressed (nice for Android)

These should help if you want to get up and running quickly with input.

CIwGameSprite hit testing

CIwGameSprite got a new method called hitTest() that lets you check to see if a point is inside a transformed sprite:

// Generate transformed vertices bool CIwGameSprite::HitTest(int x, int y) { // Generate transformed vertices int w = Width / 2; int h = Height / 2; TransformedV[0].x = -w; TransformedV[1].x = w; TransformedV[2].x = w; TransformedV[3].x = -w; TransformedV[0].y = -h; TransformedV[1].y = -h; TransformedV[2].y = h; TransformedV[3].y = h; for (int t = 0; t < 4; t++) TransformedV[t] = Transform.TransformVec(TransformedV[t]); int i1 = 0; int i2 = 3; for (int t = 0; t < 4; t++) { int x0 = TransformedV[i1].x - TransformedV[i2].x; int y0 = TransformedV[i1].y - TransformedV[i2].y; int x1 = x - TransformedV[i2].x; int y1 = y - TransformedV[i2].y; if ((x1 * y0 - x0 * y1) >= 0) return false; i2 = i1; i1++; } return true; }

This basically transforms the sprite by the sprites current transform and checks to see if a point falls inside the sprite (takes into account rotation and scaling). If you are curious about the method it uses dot products . If the points liles on the outside of any of the lines that make up the sprite then it cannot possibly be inside the polygon.

CIwGameAudio – Let there be Sound

Yes, that’s right IwGame just got audio. I basically built a wrapper on top of IwSound that lets you easily play sound effects located in a resource file as well as music. New classes include:

  • CIwGameAudio – This is the singleton that is responsible for creating, destroying and updating the audio system
  • CIwGameSound – This class represents an instantiates sound effect
  • CIwGameSoundCollection – This class represents a collection of sound effects

if you are using IwGame then you do not need to do anything except load a resource file that contains your sound effects and set the CIwGameAudio’s group like this:

CIwResGroup* AudioGroup = IwGetResManager()->LoadGroup("Audio.group"); IW_GAME_AUDIO->setGroup(AudioGroup);

You then play sound effects like this: IW_GAME_AUDIO->PlaySound(“explosion”); And music like this: IW_GAME_AUDIO->PlayMusic(“music.mp3”); Couldn’t get much simpler really However, if you want to set up and update the audio system yourself you will need to:

// Initialise audio system CIwGameAudio::Create(); IW_GAME_AUDIO->Init();

Then in your main loop, every frame call:

// Update audio IW_GAME_AUDIO->Update();

And finally on clean up call:

// Shut down audio IW_GAME_AUDIO->Release(); CIwGameAudio::Destroy();

CIwGameScene Scene Clipping

You can now set a rectangular area on a  per scene basis that all actors / sprites within that scene will be clipped to. Parts of sprites that fall outside the clipping region will not be drawn. To set up clipping simply call CIwGameScene::setClippingArea(int x, int y, int w, int h) where x and y are the top / left hand corner of the clipping area whilst w and h are the width and height. Note that clipping coordinates are not specified in pixels but in virtual canvas coordinates. The origin (0,0) is the centre of the screen. So if you virtual canvas is set to 480 x 320 pixels then use x = -240, y = -160, w = 480, h = 320 to clip to the full canvas, although you can just set w to 0 to disable clipping (that’s the default).

Well that’s it for this week, unfortunately I didn’t get the time to do a new Marmalade SDK tutorial but I will try and get that done mid next week. I have some free time coming up soon so I can knock lots of tutorials out. Also have some interesting news coming up soon about an SDK we just finished that pulls ads from inner-active and displays them all fancy 🙂 Compatible with all Marmalade deployment platforms.

8 thoughts on “IwGame Engine Update – v0.230

  1. Hey there.

    You mention for sprites : “The method currently only supports images in RGB_565 and RGB_888 format.”

    Have you found anyway to actually get marmalade to use a 24bit surface on iOS – it just seems to ignore the ICF values, and creates a RGB_565 surface …

    looks bad 🙁

  2. Only today did I find this update.

    Anyway this update contains most of what I need. I am now going to construct a game using this framework. However I would like to point out a couple of issues:

    Don’t know what is the image size limit, but medium size images create problems, can’t be allocated to memory.

    http://images.wikia.com/fantendo/images/1/17/SuperMario.png

    What is the limit, also what is the total limit using this method?

    Jpg images don’t work, simulator says there is no decoder available.

    http://alxa.ru/file/icons/super_mario.jpg

    IwAssert failure (UTIL, 1437).
    Message: NO jpg decoder implemented

    Callstack:
    CIwImage::ReadFile
    CIwImage::ReadFile
    _IwGxInitPipeline

    If the source image is bigger than canvas, we get an exception from the simulator and we get a Null passed into Iw2DDrawImageRegion(Image->getImage2D(), CIwSVec2(x, y), CIwSVec2(Width, Height), CIwSVec2(SrcX, SrcY), CIwSVec2(SrcWidth, SrcHeight));

    Other Image urls for test are: https://lh4.googleusercontent.com/-QI-Uu0iz_B8/Tqq23a8kT0I/AAAAAAAAAE4/A63ZH6g0VMw/s453/danoptimus.jpg
    My face.

    And second test image that works fine is http://rocketdock.com/images/screenshots/thumbnails/Avatar_9_256x256x32.png

    Ill try and collect more information as I keep testing this, however it seems like I may use the download image feature for another time… I can see it being used for levels and other stuff but I am not ready to have those advanced features in my prototype just yep. That would involve version checking, download management, and a bunch of other steps to work properly, but it’s really cool that it’s there already in case I need it in the future.

  3. Hey Mat,

    What are your plans for the next release?

    I am thinking about adding box2d physics, but if you are going to be doing that soonish Ill leave that in your more capable hands.

    Thanks for all the great new features.

  4. The next release will include IwGameAds, hopefully IwGameTimeline for advanced actor animation and some other bits and bobs, maybe support for accelerometer and compass. Box2D will be a fair way off yet, probably around a month or so.

  5. Hi Dan,

    Hmm, odd how that image doesn’t work. I will take a look at that tomorrow, see if I can find out what’s going on. I will also take a look at the JPEG issue. Can I ask how you are including the engine? Are you adding IwGame to your projects list in the MKB? Also, are you adding the JPEG files to the assets list or the resource group?

    Mat

  6. Hi Mat,

    The images I am just adding them using the IwGameHttp method

    image_file->Open(“http://www.battleballz.com/bb_icon.gif”, false, true);

    I simply replace the URL. It worked for gif and png files but jpg files it doesn’t. don’t know if there is a setting you have to change, I noticed in the code a boolean value named is_jpeg but I haven’t looked at the code properly yet, so there may be a setting you have to toggle for jpg?

    I am currently just using your testbed example.

    @next release: Sounds fine for me, I am actually going to check my game design and see if I need anything more than basic collision… I just remembered last night that I did not have any physics for my previous version on j2me and it worked just fine doing basic collision detection. Ill have to review my feature set for a real need to implement box2d.

  7. Yep, you currently need to mark the image as jpeg when initialising it using:

    bool Init(const char* name, void* memory_file, int memory_file_size, bool is_jpeg); // Create an image from a memory based file

    I’m going to remove this dependency in the future and check the header of the image to determine its file type.

    Was hoping to spend a lot of time with IwGame this week but unfortunately I’ve been working flat out on other projects to find the time and now I’m down with the rotten flu.

    My IwGameAds work is coming to a close so very soon I can put more focus back on core IwGame.

    Good luck with your game, let me know how it goes.

Leave a Reply