Android and iOS Market share – Who’s ruling the roust!

I recently came across this great article on techcrunch and thought it a worth while mention to you budding game and app developers.

According to this article Android now has 41.8% of the US market (up a staggering 5.8% on last quarter), whilst Apple’s iOS has a very respectable 27% (up 1% on last quarter). RIM also has a very respectable 21.7% (4% drop) and Microsoft a 5.7% share (1% drop).

From these figures it looks like Android is stealing the share from RIM and Microsoft and probably a few other lesser known platforms that share the bottom 2% of the market. I’m quite surprised to see Microsoft losing ground already considering that their offering hasn’t not long since left the gates. Maybe the new Mango update and Nokia alliance will help fix that.

With the imminent launch of Amazon’s tablet the Kindle Fire, does Apple have a fight on their hands I wonder. I think its a distinct possibility as its priced at less than half the price ($199) and Amazon have a large existing user base. Will we see Apple lose shares to Android when the Kindle Fire hits mid November 2011.

Marmalade SDK Tutorial – Handling key inputs and the on screen keyboard

This tutorial is part of the Marmalade SDK tutorials collection. To see the tutorials index click here

In today’s tutorial we are going to cover key input and on the on screen keyboard (OSK).

As usual if you just want the associated article source code then you can Download it from here. If you want the details on the updated CInput class then please feel free to read on.

Keys and Key States

Marmalade maps device keys to an enum called s3eKey. if you take a look at the Marmalade SDK header file s3eKeyboard.h you will see that the list of mapped keys is quite extensive.

Marmalade uses key states to let us know what is currently happening to all the available keys on the device, for example we make queries such as “is the back key pressed” or “is the menu key up or down”. The following states are supported:

  • S3E_KEY_STATE_DOWN – The user is holding down the key
  • S3E_KEY_STATE_UP – The key is up and not being held down by the user
  • S3E_KEY_STATE_PRESSED – The user has just pressed their finger on the key
  • S3E_KEY_STATE_RELEASED – The user has just released the key

To query the state of a particular key we need to call s3eKeyboardGetState(key), which returns the states of the specified key. Note that its possible that a key can have more than one state. For example, if the user has just pressed the key then it would have both the S3E_KEY_STATE_DOWN and the S3E_KEY_STATE_PRESSED states.

On Screen Keyboard

The on screen keyboard is a software based keyboard that is available to phones and tablets that support a touch sensitive screen (You can call s3eOSReadStringAvailable() to determine if it is supported). You can bring up the OS specific on screen keyboard quite easily using Marmalade’s s3eOSReadStringUTF8() and s3eOSReadStringUTF8WithDefault(). These blocking functions display the operating system specific keyboard and then return any entered text. Its possible to suggest to the system (by passing a flag to these functions) what kind of keyboard you want the user to be presented with to cater for different types of input. The following types are available:

  • No flags – Standard keyboard
  • S3E_OSREADSTRING_FLAG_PASSWORD – A password entry keyboard
  • S3E_OSREADSTRING_FLAG_EMAIL – An email address entry keyboard
  • S3E_OSREADSTRING_FLAG_URL – A URL entry keyboard
  • S3E_OSREADSTRING_FLAG_NUMBER – A number entry keyboard

CInput Changes

Ok, now that the basics are out the way lets take a look at the changes to the CInput class. If you haven’t read the previous article that introduced this class then you can check it out here

If you take a look at CInput.h, you will notice a few major additions. The first few additions include header files required by the key and on screen keyboard systems:

#include "s3eKeyboard.h" #include "s3eOSReadString.h"

Switching over to the CInput.cpp class source file you will notice that we have added a few extra checks into CInput::Init()

// Check to see if the device that we are running on supports the keyboard KeysAvailable = (s3eKeyboardGetInt(S3E_KEYBOARD_HAS_KEYPAD) || s3eKeyboardGetInt(S3E_KEYBOARD_HAS_ALPHA)); // Check to see if the device that we are running on supports the on screen keyboard OSKeyboardAvailable = s3eOSReadStringAvailable() == S3E_TRUE;

This code basically ensures that the modules we are wanting to use are available on the device that we are running on.

Next we add the following code to CInput::Update() to ensure that the system updates key states

// Update key system if it is available if (KeysAvailable) s3eKeyboardUpdate();

Lastly, we add code to query key states and show the on screen keyboard:

bool CInput::isKeyDown(s3eKey key) const { if (!KeysAvailable) return false; // Return down state of queried key return (s3eKeyboardGetState(key) & S3E_KEY_STATE_DOWN) == S3E_KEY_STATE_DOWN; } bool CInput::isKeyUp(s3eKey key) const { if (!KeysAvailable) return false; // Return up state of queried key return (s3eKeyboardGetState(key) & S3E_KEY_STATE_UP) == S3E_KEY_STATE_UP; } bool CInput::wasKeyPressed(s3eKey key) const { if (!KeysAvailable) return false; // Return pressed state of queried key return (s3eKeyboardGetState(key) & S3E_KEY_STATE_PRESSED) == S3E_KEY_STATE_PRESSED; } bool CInput::wasKeyReleased(s3eKey key) const { if (!KeysAvailable) return false; // Return released state of queried key return (s3eKeyboardGetState(key) & S3E_KEY_STATE_RELEASED) == S3E_KEY_STATE_RELEASED; } const char* CInput::showOnScreenKeyboard(const char* prompt, int flags, const char* default_text) { if (!OSKeyboardAvailable) return NULL; // Show on screen keyboard and return the input string if (default_text != NULL) return s3eOSReadStringUTF8WithDefault(prompt, default_text, flags); else return s3eOSReadStringUTF8(prompt, flags); }

Using the new CInput features

If we now turn our attention towards Main.cpp, we can take a quick look at what has changed from our previous Touch example.

Firstly note that we got rid of s3eKeyboardUpdate(); as this is now handled by g_Input.Update()

We have also replaced the following code:

if (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) // Back key is used to exit on some platforms break;

With this code:

if (g_Input.isKeyDown(s3eKeyAbsBSK)) // Back key is used to exit on some platforms break;

Not a great deal but a little more readable.

Now, we add a check into our main loop to see if the user has tapped the top of the screen. If they have then we show the on screen keyboard

// if user taps at top of screen then activate on screen keyboard if (touch->y < 50) { // Show on screen keyboard then print out the returned text to the debug trace const char* text = g_Input.showOnScreenKeyboard("Enter Text"); if (text != NULL) s3eDebugOutputString(text); }

If the user enters some text then we display the entered text to the debug console using s3eDebugOutputString()

Handling Android Back and Menu Buttons

Its worth noting that we’ve come across a number of Android app stores that require special handling of home and menu buttons as part of their certification process. These buttons should be implemented as follows:

  • Back Button – Navigate backwards in your application to the previous screen / menu
  • Home Button – Bring up the in-app or in-game menu

Well that concludes this tutorial. I hope you all find it of some use. You can download the associated Keys project source code from here

Happy coding and don’t sit on two legged chairs!

Marmalade SDK Tutorial – Touch and Multi-touch

This tutorial is part of the Marmalade SDK tutorials collection. To see the tutorials index click here

A little rushed this weekend but I did kind of commit myself to producing another tutorial this weekend, so here goes.

This tutorial is going to cover handling touch and multi-touch pointer events using the Marmalade SDK. Thankfully the Marmalade SDK makes this pretty simple as you will soon see.

As usual if you just want the code then grab it from here. if you want the details then read on. If you just want the details on how to use the CInput class then jump straight to the “Using CInput” section

Oh its worth noting that week by week I am going to keep updating the original Iw2D DrawSprite example with the systems that we put together. This week for example, I have added a new CInput class. I like to try and keep code for separate systems in their own neat little classes because a) it makes the code easier to understand b) you can strip out the code and use it as-is with no modification c) its good programming practice. I would ordinarily create systems such as CInput using a singleton, but for the sake of readability and so that you don’t have to run off finding out about the likes of singletons, I have simply declared the concrete version of CInput as a global (slap on the wrist for me, but whatever makes the code easier to understand)

Marmalade Events and Callbacks

The Marmalade pointer system handles screen touches using an event system. This means that when something happens to the pointer (the users finger or a stylus touches the phone or tablets screen for example) the system calls a function to handle it. The Marmalade SDK uses what are called Callbacks to implement this type of event notification system. A call back is basically a function that we define that gets called back by the Marmalade system when the event occurs. The system usually passes some parameters to the call back function to let us know what the heck it wants. Here’s a quick example:

// // HandleSingleTouchButtonCB - The system will call this callback when the user moves their finger on the screen // void HandleSingleTouchButtonCB(s3ePointerEvent* event) { // Please add code to do something about this important event }

In this example HandleSingleTouchButtonCB gets called by the system when the user touches the screen. Behold, the system has also provided us with some data about the event by way of a pointer to the s3ePointerEvent data type. We can now query this data to find out what the system wants to tell us.

Taking a quick look at the s3ePointerEvent data type we discover that there is some pretty interesting stuff in there that we can use:

typedef struct s3ePointerTouchEvent { /** * ID of the touch. The ID given to a touch is equal to the number * of simultaneous touches active at the time the touch began. This ID * can be between 0 and S3E_POINTER_TOUCH_MAX-1 inclusive */ uint32 m_TouchID; /** Whether the touch started (1) or ended (0).*/ uint32 m_Pressed; /** Position X. */ int32 m_x; /** Position Y. */ int32 m_y; } s3ePointerTouchEvent;

Ok, so some of you may be thinking, how do I tell the Marmalade SDK to use my callback when such an event does occur? Because call backs are so useful the Marmalade SDK has lots of function for registering a callback with the system. The one we are interested in for the pointer is called:

S3E_API s3eResult s3ePointerRegister(s3ePointerCallback cbid, s3eCallback fn, void* userData);
  • cbid – This represents a constant that identifies which pointer event you would like to be notified about
  • fn – The address of the callback function that you would like Marmalade to call when the event occurs

Here’s how we would set one up to listen for single touch events

s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)HandleSingleTouchButtonCB, NULL);

Now that is registered, whenever the system receives a screen touched event you will know about it as HandleSingleTouchButtonCB() will be called

Oh and be nice to the system and don’t forget to unregister the call back when you are done using it with, such as when you exit the game:

s3ePointerUnRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)HandleSingleTouchButtonCB);

Types of Marmalade Pointer Events

The Marmalade SDk currently handles a number of pointer event types:

  • Touch Event – Called when the user touches the screen (S3E_POINTER_BUTTON_EVENT)
  • Motion Event – Called when the user moves their finger or stylus on the screen (S3E_POINTER_MOTION_EVENT)
  • Multi-touch Touch Event – Called when the user touches the screen (S3E_POINTER_TOUCH_EVENT)
  • Multi-touch Motion Event – Called when the user moves their finger or stylus on the screen (S3E_POINTER_TOUCH_MOTION_EVENT)

To be a good Marmalade developer you should handle all four of these events

Handling the Four Marmalade Pointer Events

In the Input example (CInput.cpp) we have declared four call backs to handle all four events:

// // HandleMultiTouchButtonCB - For multitouch devices the system will call this callback when the user touches the screen. This callback is called once for each screen touch // void HandleMultiTouchButtonCB(s3ePointerTouchEvent* event) { // Check to see if the touch already exists CTouch* touch = g_Input.findTouch(event->m_TouchID); if (touch != NULL) { // Yes it does, so update the touch information touch->active = event->m_Pressed != 0; touch->x = event->m_x; touch->y = event->m_y; } } // // HandleMultiTouchMotionCB - For multitouch devices the system will call this callback when the user moves their finger on the screen. This callback is called once for each screen touch // void HandleMultiTouchMotionCB(s3ePointerTouchMotionEvent* event) { // Check to see if the touch already exists CTouch* touch = g_Input.findTouch(event->m_TouchID); if (touch != NULL) { // Updates the touches positional information touch->x = event->m_x; touch->y = event->m_y; } } // // HandleSingleTouchButtonCB - The system will call this callback when the user touches the screen // void HandleSingleTouchButtonCB(s3ePointerEvent* event) { CTouch* touch = g_Input.getTouch(0); touch->active = event->m_Pressed != 0; touch->x = event->m_x; touch->y = event->m_y; } // // HandleSingleTouchMotionCB - The system will call this callback when the user moves their finger on the screen // void HandleSingleTouchMotionCB(s3ePointerMotionEvent* event) { CTouch* touch = g_Input.getTouch(0); touch->x = event->m_x; touch->y = event->m_y; }

Eik! I know, looks a bit messy, but callbacks usually do look a bit out of place. That said I do love callbacks!

The call back functions are very small and very simple. They basically pull the event data (pointer position and button status) and move them into a CTouch array inside the CInput class, where we can later access them in our code. Note the use of my nasty global concrete version of CInput g_Input. Ordinarily I would use a singleton for stuff like this (mental note, topic for another blog)

Now that callbacks are more or less out of the way we will proceed with looking at the CInput class in a little more detail

The CInput Class

Firstly lets take a look at the CInput initialisation code:

bool CInput::Init() { // Check to see if the device that we are running on supports the pointer Available = s3ePointerGetInt(S3E_POINTER_AVAILABLE) ? true : false; if (!Available) return false; // No pointer support // Clear out the touches array for (int t = 0; t < MAX_TOUCHES; t++) { Touches[t].active = false; Touches[t].id = 0; } // Determine if the device supports multi-touch IsMultiTouch = s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE) ? true : false; // For multi-touch devices we handle touch and motion events using different callbacks if (IsMultiTouch) { s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)HandleMultiTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)HandleMultiTouchMotionCB, NULL); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)HandleSingleTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)HandleSingleTouchMotionCB, NULL); } return true; // Pointer support }

Like any good programmer we are checking to ensure that the pointer system is available on the device that we are running on, with so many different handsets out there, who knows if there are some with no pointer support?

// Check to see if the device that we are eunning on supports the pointer Available = s3ePointerGetInt(S3E_POINTER_AVAILABLE) ? true : false;

Its better to know up front and inform the user that your game or app is not compatible with their phone because it does not support the pointer.

Next, we determine if the device supports multi-touch. Note that many Android phones and tablets do not support multi-touch, so you will have to think carefully about your game or apps design before targeting Android.

// Determine if the device supports multi-touch IsMultiTouch = s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE) ? true : false;

Lastly, we register two callbacks depending upon whether or not the device supports multi-touch:

// For multi-touch devices we handle touch and motion events using different callbacks if (IsMultiTouch) { s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)HandleMultiTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)HandleMultiTouchMotionCB, NULL); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)HandleSingleTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)HandleSingleTouchMotionCB, NULL); }

Ok, so now we have initialised the input system using g_Input.Init(); we need to ensure that the pointer system gets regularly updated. To do that we call g_Input.Update();

This method is very simple:

void CInput::Update() { // Update the pointer if it is available if (Available) s3ePointerUpdate(); }

Update() simply calls the Marmalade SDK’s s3ePointerUpdate() function to update the pointer system and call our callbacks when pointer events occur. Note that this must be called every game frame, so ensure that its placed somewhere in your main loop (near the beginning if possible)

Using the Cinput Class

If we now turn our attention towards Main.cpp, we can take a quick look at what has changed from DrawSprite_Iw2D.

Well the first thing is the inclusion of the CInput.h header file.

Next we initialise the Cinput class:

// Initialise the input system g_Input.Init();

Because the example supports multi-touch we create a few variables to hold the position of our two sprites so we can move them independently

int sprite1_pos_x = surface_width / 2; int sprite1_pos_y = surface_height / 2; int sprite2_pos_x = surface_width / 2; int sprite2_pos_y = surface_height / 2;

In our main loop we update the sprites based on where the user touches the screen:

// Update pointer system g_Input.Update(); if (g_Input.getTouchCount() != 0) { // Get the first touch position CTouch* touch = g_Input.getTouch(0); if (touch != NULL) { sprite1_pos_x = touch->x; sprite1_pos_y = touch->y; sprite2_pos_x = sprite1_pos_x; sprite2_pos_y = sprite1_pos_y; } // if multi-touch is available then move 2nd sprite to 2nd touch position if (g_Input.isMultiTouch()) { if (g_Input.getTouchCount() > 1) { touch = g_Input.getTouch(1); if (touch != NULL) { sprite2_pos_x = touch->x; sprite2_pos_y = touch->y; } } } }

Ok, this bit of code is no longer a bit of code and looks a bit meaty. However, it is very simple to understand.

Firstly we check to see if there has been any touches by getting the touch count from CInput. If there are touches present then we get the first touch and set both sprites to the position of the touch. This will move both sprites to wherever the user taps the screen.

The second part checks to see if there has been more than one touch, if so then we get the 2nd touch and move the 2nd sprite to its position.

Note that I am just getting the touches by their index in the touches list and not by their ID. In a proper multi-touch system you should ideally track touches by their ID and not their index in the touches list. But for this example, this way suffices.

And finally we draw our sprites at their new positions:

// Draw two sprites DrawSprite(image1, sprite1_pos_x, sprite1_pos_y, -sprite_angle, (iwfixed)(IW_GEOM_ONE * 2)); DrawSprite(image2, sprite2_pos_x, sprite2_pos_y, sprite_angle, IW_GEOM_ONE);

Multi-touch Simulation using the Simulator

The Marmalade SDK simulator will allow you to simulate multi-touch functionality in your application but you firstly need to enable it. To enable this functionality you need to:

  • Go to the simulator menu and select Configuration Pointer
  • Tick “Report multi-touch available” and “enable multi-touch simulation mode”

Now that you have enabled multi-touch simulation you can use the middle mouse button to place touches. You can move the touches around by holding the middle mouse button down over the placed touch and move it. To remove a multi-touch touch, simply click the middle mouse button over the touch again.

Well that concludes this tutorial. I hope you all find it of some use. You can download the associated touch code project from here

Happy coding and stay away from rickety old bridges!

Marmalade SDK Tutorial – Up and Running in a Jiffy – The Main Game Loop

This tutorial is part of the Marmalade SDK tutorials collection. To see the tutorials index click here

Ok, so you downloaded and installed the Marmalade SDK, took a quick scan over the help files and thought “Hmm, this is a biggy, where do I start?” When we start something new we all feel like complete and utter noobs. Al you want to do is get a “hello world” application up and running so you can have some kind of sense of achievement and feel comfortable with the process of updating code, compiling it and seeing it actually working. With this in mind, this tutorial will help you accomplish just that. On the other hand, if you just want the source code to the tutorial then you can download it here.

By the way, if you haven’t already done so then http://www.madewithmarmalade.com/download and grab a copy of the free trial version of the Marmalade SDK and install it.

We will begin with a few Marmalade basics so you don’t get lost during the tutorial.

Project files (MKB’s)

To begin with, Marmalade uses the concept of project files to organise your source files, data files and deployment settings. The MKB file is basically a text file that when opened up will generate a Visual Studio or XCode project containing your source files etc.

The MKB file is split into a number of sections, each with a heading name followed by curly braces containing the sections data. Here’s an example of a section:

subprojects { iw2d }

For now you only need to be concerned with the following basic sections of the MKB:

  • options – Options to pass to the build system
  • includepath – Tells marmalade where to look for your header files
  • subprojects – This section tells Marmalade which parts of the SDK you would like to use. Here you put the names of the SDK parts you would like to access from your code, for example, the 2D API is called Iw2D
  • files – This section tells Marmalade which editable files you would like including in your generated project, such as source files, XML files, configuration files etc..
  • assets – This section tells Marmalade which assets you would like to include when deploying your app or game, assets include files such as bitmaps, audio files, meshes, fonts, data files etc.. You can define assets in groups if you need a particular set of assets specific platforms
  • deployments – This section allows you to define certain parameters on a per target platform basis. We won’t be covering this section in this tutorial but its worth mentioning.

Ok, now we have explained a few things about MKB files, here is a very basic one to get you started:

#!/usr/bin/env mkb options { } subprojects { iw2d } includepath { ./source } files { [Source] (source) Main.cpp } assets { }

To generate a project from this file you need to:

  • Create a folder on your hard drive, lets call it BasicMKB
  • Create a text file called BasicMKB.mkb and add the above lines to it
  • Create a sub folders called source
  • Add a Main.cpp file to the source folder
  • Double click the BasicMKB.mkb file to have the Marmalade SDK generate your Visual Studio or XCode project

Notes:

  • Marmalade will generate a data folder containing two .icf files and a build folder, you do not need to be concerned with these for the time being.
  • You should not add additional source files via XCode or Visual Studio. instead, edit the MKB file, add your source files then re-launch the MKB file regenerate the project.

Now we are finally have the basics of creating a Marmalade SDK project out of the way, we now need something to compile and run.

A very basic game loop

In this section we will cover creating a very basic game loop that checks for the user quitting and clears the screen.

Ok, re-using the previous example, you need to edit the Main.cpp file that you created and add the following code:

// Marmalade headers #include "s3e.h" #include "Iw2D.h" #include "IwGx.h" int main() { // Initialise Marmalade graphics system and Iw2D module IwGxInit(); Iw2DInit(); // Set the default background clear colour IwGxSetColClear(0x40, 0x40, 0x40, 0); // Main Game Loop while (!s3eDeviceCheckQuitRequest()) { // Update keyboard system s3eKeyboardUpdate(); if (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) // Back key is used to exit on some platforms break; // Update pointer system s3ePointerUpdate(); // Clear the screen IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); // Update the game // Render the games view // Show the surface Iw2DSurfaceShow(); // Yield to the operating system s3eDeviceYield(0); } // Shut down Marmalade graphics system and the Iw2D module Iw2DTerminate(); IwGxTerminate(); return 0; }

You can download a zip archive containing the project MKB and source code from here

If you build and run this example you will be presented with a grey screen. yes I know its a bit boring, but we will cover drawing sprites and other interesting topics very soon.

Hello Marmalade – Introduction to the Marmalade SDK – The ultimate cross platform SDK for smart phones and tablets

This tutorial is part of the Marmalade SDK tutorials collection. To see the tutorials index click here

So you are a smart phone, tablet, smart TV or desktop developer (or at least want to be) and you want to have your next hit game or app run across a huge range of smart phones and tablets. Well, you have come to the right place to find out how to do just that.

No matter whether you are a professional games developer, part time hobbyist coder or the technical director of a large corporation researching how to support you work force across a huge range of varied phones and tablets, the basic principles remain the same. By choosing to develop your products across multiple platforms:

  • You benefit from a much wider audience for your apps and games
  • You save a lot of money and time on development, testing and updating
  • You can perform updates to your existing apps quickly and easily
  • You can share the same unified C / C++ code base across all devices and platforms
  • No need to learn (or hire professionals that know) multiple languages, UI’s or SDK’s
  • Regularly updated SDK with new platforms and features
  • Some of the smaller app stores offer increased visibility and more stable long term sales

And by choosing the Marmalade SDK you also get:

  • A FREE license/li>
  • Amazing support, including the apps program and device loan program to aid testing
  • A simulator that lets you test across an unlimited set of screen resolutions and simulated access to Accelerometer, GPS, Camera, Audio, Multi-touch screen, SMS, Compass and more
  • Test actual ARM code without even deploying to an ARM based device
  • Support for iOS specific features such as App Store Billing, iAd, Game Center etc..
  • Support for Android specific features such as Android Market Billing
  • Access to a large collection of open API’s such as Box2D, AdMob, Flurry, Chipmunk,SVG, Python, LUA and tonnes of other cool stuff (Full list available at http://github.com/marmalade)

Marmalade is also partnered with the likes of Shiva3D, Scoreloop, Tapjoy, Raknet and many others, so you know this is an SDK that’s here to stay

Ok so what platforms does Marmalade actually support? The list to date is as follows:

  • iPhone, iPod Touch and iPad
  • Android
  • Blackberry Playbook
  • Blackberry 10
  • Windows
  • Windows Phone 8
  • OSX
  • Tizen
  • Roku

I know what you are thinking, can I really write my code once and run it across all of these platforms? The straight answer is “absolutely!” as we at Pocketeers have proven. We have already released BattleBallz Chaos (Arcade action game) across iOS, Android, Bada and Blackberry Playbook using the Marmalade SDK, as well as Funky Cam 3D (a fun photography app) across iOS, Android and Bada.

Ok, so if you can write your code once and deploy to so many platforms then why is your BattleBallz Chaos not available on the likes of Symbian or webOS? The simple answer is that some of those platform markets are not currently where we want to go for a variety of reasons, but none of those reasons relate to the Marmalade SDK. We may choose to support them in the future and we may not.

Righty ho, you’ve decided that you quite like the sound of this Marmalade SDK and you’re considering saving yourself a boat load of time and money developing your cross platform games and apps, but what does code look like with this SDK?

Well here’s a basic game loop:

#include “IwGx.h”

int main()
{
    // Initialise Marmalade graphics system
    IwGxInit();

    // Main Game Loop
    while (!s3eDeviceCheckQuitRequest())
    {
        // Clear the screen and depth buffer
        IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);

        // Update my awesome game
        PleaseUpdateMyGame();

        // Render my awesome games view
        RenderMyGameViewThankyou();

        // Flush graphics system
        IwGxFlush();

        // Display the rendered frame
        IwGxSwapBuffers();

        // Yield to the operating system
        s3eDeviceYield(0);
    }

    // Shut down Marmalade graphics system
    IwGxTerminate();

    return 0;
}

You will find that the graphical system in Marmalade is similar to Open GL, which for me makes the SDK very simple to use. All other sub systems are equally as easy to use for example:

To create a texture from a bitmap file and upload it to the GPU:

CIwTexture* texture = new CIwTexture();
texture->LoadFromFile(“AwesomeSpriteAtlas.png”)
texture->Upload();

As you can see the code is ultra simple and very easy to use but most of all “cross platform compatible!”. Imagine having to do this on iOS using XCode / Objective C and then again using Java on Android and then again using Flash on Playbook, the list goes on.

So unless you enjoy self punishment, lots of extra work and the pain of tracking the same bugs across multiple SDK’s, languages and platforms, I suggest you take a short trip over to Marmalade’s SDK home page at http://www.madewithmarmalade.com. Take a look at the SDK, its features, read some tutorials and even sneak a peek in the forums (I bite but not many of the other developers do!)

Over the coming weeks / months I will be writing a number of tutorials covering various aspects of the Marmalade SDK, associated tools and extensions, so keep an eye out.

Marmalade SDK and Blackberry Playbook – From Setup and Deployment to App World Submission

The latest version of the marvellous Marmalade SDK 5.1.3 has recently hit our development machines. Whats so special about 5.1.3 you ask? Well for starters you can now deploy your smart phone and tablet apps and games to the awesome Blackberry Playbook. If you haven’t had the chance to tinker with one of these beauties then I suggest you go and have a play because they are fantastic tablets. Amazon are selling them right now here for 16GB version and here for 64GB version

Ok you read this far and thought, “hmm, what the hell is the Marmalade SDK fool?”, sounds like something you would spread on toast and not actually use to make ground breaking cross platform games and apps. For those developers that have been asleep for the last couple of years or maybe just missed the name change, the Marmalade SDK is the newly named AirPlay SDK created by the boffins over at IdeaWorks. The marmalade SDK is basically an awesome system that allows developers to develop apps and games using a single unified API for a whole host of platforms including Apple iPhone, iPad, Android phones & tablets, Samsung Bada, Blackberry Playbook, Web OS, Symbian, Windows Mobile, Windows, Mac and others. How do they do that you may ask, well don’t ask me! take a trip over to http://www.madewithmarmalade.com and take a look

Ok, shameless plug for my favourite SDK of all time out of the way, now on with the article

We have recently just ported one of our games “BattleBallz Chaos” to the Blackberry Playbook platform and had it published in record time (for our company at least). Within 24 hours we went from receiving our Blackberry Playbook test tablet and our unified Android, iOS, Bada code base to “on the App World store!” For those interested you can check out BattleBallz Chaos here and more info about our other versions for iPhone, iPad, Android, Bada and Windows Phone 7 is at http://www.battleballz.com

BattleBallz Chaos Blackberry Playbook Screen Shot
BattleBallz Chaos in action on the Blackberry Playbook

You are probably here because you are pulling your hair out trying to accomplish one of the following:

  • Deploy a debug build to an actual Blackberry Playbook tablet
  • Having trouble getting your build ready for submission to RIM’s Blackberry App World store
  • Need to know the splash screen, icon formats and sizes for a Blackberry Playbook build
  • Other random issues with Marmalade or Blackberry Playbook deployment or submissions

Well for whatever reason I hope this article can help you in some small way, now on with the article

Preparing your system

1. Grab a copy of the Blackberry Web Works SDK from http://us.blackberry.com/developers/tablet/webworks.jsp. Note that you will also have some other tools to install which are listed on that same page, just follow the instructions
2. Install the SDK to your development machine as specified

You may be wondering why you would need to install the HTML5 SDK when you are deploying a native application. The reason is that you need the binary tools that are located in this SDK. Note that the native SDK is Beta at the moment and is only available by asking Blackberry directly for access to the beta program at http://03268fe.netsolhost.com/bbbeta/

Set up your PC to allow signing with the Blackberry signing server: (Only has to be done once)

3. Go to Blackberrys online code signing keys request tool at https://www.blackberry.com/SignedKeys/, fill in the information and submit,. You will be emailed 2 registration files that look something like this (DONT FORGET YOUR PIN!):

  • client-RDK-195133201.csj – This is for the signing process (RBK)
  • client-PBDT-195133201.csj – This is for the debug token creation process (PBDT)

NOTE: It may take a few days to get the registration files so apply for them immediately

4. Now lets actually do the set-up process

* Copy the registration files from step 3 into a folder (lets call it ‘Playbook’)
* Open up a command prompt and change to the ‘Playbook’ folder you just created
* Run the following commands at the command prompt:

"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-keytool" -genkeypair -keystore sigtool.p12 –storepass {your_password} -dname "cn={your_company_name}" -alias author
"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-signer" -csksetup -cskpass {your_password}
"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-signer" -register –csjpin {your_pin} -cskpass {your_password} client-RDK-195133201.csj

{your_password} – Choose a password that you are going to remember
{your_company_name} – Company name as specified when you requested the registration files in step 3
{your_pin} – The pin you created when you requested the registration files in step 3
client-RDK-195133201.csj – Change this to the name of the RDK CSJ file that you received in your registration files email in step 2

NOTE: The location where the blackberry-keytool and blackberry-signer will probably be different depending on which SDK you are using and where you installed it

Set up your PC to enable generation of debug tokens (Only has to be done once)

5. Open up a command prompt and change to the ‘Playbook’ folder created in step 4 then enter the following at the command prompt

"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-debugtokenrequest.bat" -register -cskpass {your_password} -csjpin {your_pin} client-PBDT-195133201.csj

{your_password} – The same password that you chose in step 4
{your_pin} – The pin you created when you requested the registration files in step 3
client-PBDT-195133201.csj – Change this to the name of the PBDT CSJ file that you received in your registration files email in step 2

Generate a debug token to allow deployment of debug builds to the Blackberry Playbook tablet

6. Open up a command prompt and change to the ‘Playbook’ folder created in step 4 then enter the following at the command prompt

"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-debugtokenrequest" -cskpass {your_password} -keystore sigtool.p12 -storepass {your_password} -deviceId 0x{device_id} name_of_your_debug_token.bar

{your_password} – The same password that you chose in step 4
{device_id} – Your Blackberry Playbooks device ID
name_of_your_debug_token.bar – Note that you should not use any funny characters or spaces in this name, best bet is to name it something like companynamedebugtoken.bar

NOTE: To find your Blackberry Playbooks device id do the following:
* Tap the settings icon in the top right hand corner of the playbooks screen to bring up settings
* Select “’About ‘ item on the left hand side menu
* In the drop down box to the right selected “’Hardware’
* The ‘PIN’ number shown is your device ID

Install the debug token to the Blackberry Playbook tablet

7. if you haven’t already done so then ensure that you have connected your Playbook to your local Wi-Fi network. Go to Settings->Wi-Fi and set it up here.
8. Go to settings->About then select ‘Network’ from the drop down list to the right which displays info about your network. Now note down the IP address of the Playbook (something like 192.168.1.2)
9. Enable “Development Mode” on your Blackberry Playbook as follows:

* Go to Settings->Security->Development Mode
* Slide the development mode slider to “On”
* You will be asked to enter a password (for simplicity use the same password as you use for logging into your Playbook)
* Select “Upload debug token” button

And finally to install the debug token to the Playbook, open up a command prompt and change to the ‘Playbook’ folder created in step 4 then enter the following at the command prompt to install the debug token to the Playbook

"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-deploy" -installDebugToken name_of_your_debug_token.bar –device {ip_address} –password {playbook_password}

name_of_your_debug_token.bar is the name of your debug token that you create in step 6
{ip_address} – The IP address that you noted down in step 8
{playbook_password} – This is the security password that you have set for your Blackberry Playbook (The one you type in when you log into your Playbook)

Ok, the hard bit is out of the way, take a breather and go for a coffee, next part is deploying via the Marmalade SDK, which is thankfully a much easier process

Deploying your Marmalade SDK app to the Blackberry Playbook tablet

There are a few things you need to do on the Marmalade side in order to get your build ready for deployment to the Blackberry Playbook:

10. MKB project file modifications

* If you want to appear as the author for your app then you need to add the following to the Playbook deployment section of your MKB:

playbook-author='Your company name'

* So that RIM can identify you as the real author of the app they need to know your author ID. The line in your MKB will look something like this:

playbook-authorid='gBACAgDE-PVmaTowNV2UQzp61q32'

The aiuthor-id is however a little elusive. The easiest way to find it is to rename the “name_of_your_debug_token.bar” file that you generated in step 6 as a zip file “name_of_your_debug_token.zip” for example. Open the zip file and extract the MANIFEST.MF file. open this file in a text editor and fiind the field called “”Package-Author-Id” the value for this field is the authorid you need to supply to the Marmalade build system

* To set the Splash Screen and icon use the following two MKB commands:

splashscreen=PlaybookSplash.png
icon=PlaybookIcon.png

The splash screen and icons will be scaled to the correct sizes, but I recommend choosing a large sized splash screen that matches the 1024 x 600 pixel aspect ratio screen and 86 x 86 pixel icon (rounded corners and transparency are allowed in the icon)

Ok, now you have this in place, compile and run your ARM release build. When the Marmalade deployment tool runs and gets to the final stage of deployment you need to enter the following details:

* Device hostname (or IP address) – Enter the IP address that you noted down in step 8
* Device password – Enter your playbook security password (The one you type in when you log into your Playbook)

If you selected Package and Install in the previous Marmalade deployment step then you should find your apps shiny icon on the Playbooks screen (under games category most likely)

Ok, you can now deploy your build to an actual Blackberry Playbook, but what about preparing your BAR file for submission to Blackberry App World, we shall cover that next

Preparing your app for submission to the Blackberry App World Store

In order to submit your app to Blackberry for App World approval you will need to sign your BAR file:

11. Edit the file located at “\Marmalade\5.1\s3e\deploy\plugins\qnx\MANIFEST.MF” and change the line that reads “Application-Development-Mode: true” to “Application-Development-Mode: false”. Remember to change it back to true when you are deploying development builds
12. Open up a command prompt and change to the folder where you MKB is located (lets say for example ‘e:\Apps\CoolGame’)
13. Copy the file ‘sigtool.p12’ from the ‘Playbook’ folder that you created in step 4 into the folder specified in step 12
14. Run the following commands at the command prompt: (when resigning the same build you only need to perform steps 12 and 14)

"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-signer" -verbose -cskpass {your_password} -keystore sigtool.p12 -storepass {your_password} build_coolgame_vc10\deployments\Blackberry\playbook\release\CoolGame.bar RDK
"E:\Program Files\Research In Motion\BlackBerry WebWorks SDK for TabletOS 2.1.0.6\bbwp\blackberry-tablet-sdk\bin\blackberry-signer" -keystore sigtool.p12 -storepass {your_password} build_coolgame_vc10\deployments\Blackberry\playbook\release\CoolGame.bar author

{your_password} – The same password that you chose in step 4
build_coolgame_vc10\deployments\Blackberry\playbook\release\CoolGame.bar – You need to replace this section with the relative path to your .BAR file for your app

You now have a signed BAR file that you can submit to Blackberry App World for approval! Good luck with your submission and good luck with sales!

A Few Notes

* You can choose a separate CSK password and store password if you like to increase security
* Remember to replace the path to the Blackberry tools with the correct path for your Blackberry SDK install
* Our app only took around 16 hours to get approval but we noticed that the number of new apps appearing around our time of submission were few and far between so it could take longer
* Ensure you have a working internet connection throughout the whole process as the Blackberry tools will need to query various external servers
* If you are having trouble with deploying your debug build then ensure that a) Your Blackberry Playbooks IP address has not changed and b) Your debug token has not expired (they have a very short life span)
* If you would like your app to be classified in a category other than “’games’ you will need to change the application category line “Application-Category: core.games” located in the file “\Marmalade\5.1\s3e\deploy\plugins\qnx\MANIFEST.MF”

Confirming that your app has been signed

To confirm that you app has been signed by both the RIM signing authority and yourself open your BAR file as a zip file and check the META-INF folder. This folder should contain 5 files:

* AUTHOR.EC
* AUTHOR.SF
* MANIFEST.MF
* RDK.EC
* RDK.SF

If any are missing then something went wrong and you need to sign again. Note that if you receive an error saying something along the lines of “already signed” then change your version number, rebuild and re-sign