AppGameKit Studio has a set of core commands that deal with aspects such as finding out the width and height of a device, updating the screen, checking the orientation of a screen and finding out what device your application is running on. In this example we'll explore the usage of these commands and also look at a typical layout for an AppGameKit Studio program.
A typical AppGameKit Studio program will follow this process:
Here's the process laid out in code:
` load resources
` create sprites
` set up a simple loop do ` handle logic
` update the screen loop
` save any settings such as state of the game
` clear resources
As mentioned previously the core commands within AppGameKit Studio allow you to retrieve information about the device and handle things such as updating the screen. In the code that follows we'll explore a few of these commands in practice.
Our program will do the following:
To retrieve the width and height of the device our program runs on we call the commands GetDeviceWidth and GetDeviceHeight. These commands return these values to us and have no parameters:
width = GetDeviceWidth ( ) height = GetDeviceHeight ( )
On some platforms the orientation of the screen will be of no particular interest, such as with Microsoft Windows and Mac OS X. The reason for this is that we can expect the orientation to always be the same. On mobile devices this is not necessarily the case. Users may be holding the device in any one of 4 possible orientations e.g. portrait, portrait flipped, landscape and landscape flipped. Retrieving this is useful as it allows you to customise your game dependent on the current orientation. Finding the orientiation is achieved with a simple call to the command GetOrientation. This commands returns 1 for portrait, 2 for portrat flipped, 3 for landscape and 4 for landscape flipped. It has no parameters:
orientation = GetOrientation ( )
There may be instances when it's necessary to determine what platform or device your program is running on. This is useful for cases when you may require some platform specific behaviour. To find out the platform your program is running on call the command GetDeviceName. This command returns a string that will contain one of the following:
The command can be called like this:
platform = GetDeviceName ( )
AppGameKit Studio will not display anything on screen until the command Sync is called. To ensure the screen is updated call this command within your main loop.
Everything is now in place. Here's the final code for our program:
width = GetDeviceWidth ( ) height = GetDeviceHeight ( )
orientation = GetOrientation ( )
platform$ = GetDeviceName ( )
do print ( width ) print ( height ) print ( orientation ) print ( platform$ )
Sync ( ) loop
Several other commands are included with the core section. Please refer to the reference guide for more details.