Friends with AirPlaySDK

It's no secret that coding for mobile phones is an interesting, profitable and promising business. I always start some kind of game on the PDA when I go down the subway and see how the people around me do the same. But unfortunately the current variety of platforms often forces us to limit the range of supported devices.

Ideaworks Labs took care of us and created AirPlaySDK. This toolkit allows you to write C ++ code once and compile it into native applications for iOS, Android, Samsung Bada, Symbian, Windows Mobile, BREW, Palm / HP WebOS and Maemo platforms. Well, how impressive? In addition, AirPlaySDK has excellent documentation (though in English) and allows you to use the unique features of a particular platform. You can download and try AirPlaySDK from the website for free.www.airplaysdk.com or buy an Indie license for only $ 99, and iPhone developers the right to use this toolkit is free (that is, for free).

Project creation


AirPlaySDK allows you to write applications on Windows or Mac OS, and integrates well with Visual Studio (starting with version 6.0) and Xcode, respectively. I will focus on Visual Studio, but I'm sure that for Xcode everything will look no more complicated.
So, you have downloaded and installed AirPlaySDK and Visual Studio. Create a HelloWorld folder anywhere on your drive. It is in this folder that our first project will be placed.
The main file of the whole solution is HelloWorld.mkb in the HelloWorld folder , create and open it for editing and write the following contents there:

options {
        s3e-data-dir="data"
}
files {
        (source)
        HelloWorld.cpp
        HelloWorld.h
        HelloWorldMain.cpp
}
subprojects {
        iw2d
}


Here, the s3e-data-dir parameter of the options section defines the folder in which the resources of the future application will be located. It can be images, music or something else. Create the data folder declared by us in the HelloWorld folder .

The files section describes the list of project files. In parentheses we specified the source folder , which should also be created. In it we will place three files: HelloWorld.cpp , HelloWorld.h and HelloWorldMain.cpp .

The subprojects section contains the names of the libraries that we want to use in our project.

Cross-platform “Hello World!”


So, the preparation of the project is completed and we can start programming. To do this, double-click on the HelloWorld.mkb file and you will see the AirPlaySDK logo first, and then the project in Visual Studio will open in front of you. Type the code below into the HelloWorldMain.cpp file , but for now I'll explain what’s here and what’s for.

#include "s3e.h"
#include “HelloWorld.h”
int main() {
	GameInit();
	while (true) {
		s3eDeviceYield(0);
		s3eKeyboardUpdate();
		bool result = GameUpdate();
		if ((result == false) ||
			(s3eKeyboardGetState(s3eKeyEsc) &
			S3E_KEY_STATE_DOWN) ||
			(s3eKeyboardGetState(s3eKeyLSK) &
			S3E_KEY_STATE_DOWN) ||
			(s3eDeviceCheckQuitRequest()))
		break;
		GameRender();
	}
	GameShutdown();
}


Using the #include “s3e.h” directive, we include the standard AirPlaySDK header file, which enables us to work with a mobile device. We will write the GameInit ()

function ourselves. It will initialize the variables we need, create objects in every possible way, load resources and perform other actions immediately at the start of the program. The s3eDeviceYield (..) function stops the operation of the device for the time specified in the parameter and enables the operating system to perform some actions. As a parameter of this function, we passed zero, and therefore we get the minimum possible delay allowed by the operating system. s3eKeyboardUpdate ()



updates the information on the current state of the keys of the mobile phone and checks if the user has pressed any keys during the passage of the cycle. We also write the GetUpdate ()

function ourselves. As usual, it usually contains the entire logic of the application. If you are writing a game, then in this function you should check whether the next monster has died after a user shot. It should be noted that the function returns true if the application continues to work, or false if, for example, the user clicked “Quit the game”.

The following is a check to see if the user wants to exit the application by pressing the corresponding menu item or phone key, and if the operating system asks our application to complete, and if the result is positive, it completes the main cycle. If the application should continue to work, move on.

In GameRender () , which we again will create on our own, there is a drawing of everything and everything on the screen. And finally, GameShutdown () (the fourth function that has not yet existed) terminates our application, saving the results, freeing memory and performing other operations.
Well, we’ve reviewed the main function of the application. It is worth noting that the file HelloWorldMain.cppIs a template. Such a file with almost the same content will be present in all projects that you will create using AirPlaySDK.

We describe the application logic


Now is the time to deal with functions that will directly determine the application logic. To do this, open the HelloWorld.cpp file and drive in the code:

#include "Iw2D.h"
void GameInit() {
	Iw2DInit();
}
bool GameUpdate() {
	return true;
}
void GameRender() {
	Iw2DSetColour(0xFF000000); 
	Iw2DFillRect(
		CIwSVec2(0, 0),
		CIwSVec2(Iw2DGetSurfaceWidth(),
			Iw2DGetSurfaceHeight())
        );
	Iw2DSetColour(0xFF00FF00);
	Iw2DFillArc(
		CIwSVec2(Iw2DGetSurfaceWidth()/2,
			Iw2DGetSurfaceHeight()/2),
		CIwSVec2(30, 30),
		0,
		0x800 * 2
		);
	Iw2DSurfaceShow();
}
void GameShutdown() {
	Iw2DTerminate();
}


As you already noticed, the code for the HelloWorld.cpp file contains the functions that I promised to describe. There is nothing complicated about this listing. He just paints the screen black and displays a green circle in the middle.

Now it’s worth describing the prototypes of these functions in the HelloWorld.h header file so that they can be called from the main function main () . It will look like this:

#ifndef HELLOWORLD_H
#define HELLOWORLD_H
void GameInit();
bool GameUpdate();
void GameRender();
void GameShutdown();
#endif


The listing does not need comments. Our application code is ready and you can run it by pressing the F5 key in Visual Studio. An emulator window will open before you, which will demonstrate our first creation on AirPlaySDK.

Project assembly


Well, it's time to demonstrate the main advantage of AirPlaySDK - portability of applications from one platform to another.

Select “GCC (ARM) Release” as the active project configuration and press F5. You will see the Airplay System Deployment Tool window. check “ARM GCC Release” and click “Next”. The next step is nothing interesting for us so far, so click “Next” again. This is where the variety of platforms for which we want to compile our application is required to be noted. Let's mark the Bada OS, click “Deploy All” and wait for the compilation of our project to finish.

PS In addition to two-dimensional graphics, AirPlaySDK makes it possible to create three-dimensional games , work with GPS, sounds, contact lists, a network, video and a bunch of other things.

UPD For some time now, the Airplay SDK has been renamed the Marmalade SDK.

Also popular now: