DragonFireSDK

FlameUpLeft

© 2012 Zimusoft, Inc. DragonFireSDK 2.0

 

Contact us: support@DragonFireSDK.com

 

Getting Started

 

It’s easy to see your first iPhone application running. This section should help get you started – don’t worry, you’ll have an application running in the Windows iPhone Simulator in about 15 minutes.

 

A DragonFireSDK application requires these three functions:

 

AppMain()

AppExit()

OnTimer()

 

Just as any C program requires a main() function as a starting place, DragonFireSDK applications need a function called AppMain(). This function is the first thing to run – it’s your chance to load images and initialize variables.

 

OnTimer() is executed 30 times per second. This is where you update image locations and keep the game running. In animation terms, it runs each frame and frames are presented 30 times per second. This is sometimes referred to as the GameLoop.

 

An example will explain. The code below will compile and run showing a ball on the screen. The ImageAdd function adds an image (loads an image into memory). The ViewAdd() adds a view (creates a view to visibly present an image on the screen). As you will see later, you will sometimes load 20 frames of animation as images and use only one view - you just change which image that view is displaying at the time.

 

#include "DragonFireSDK.h"

 

int BallImage;

int BallView;

 

void AppMain() // the program begins here

{

  BallImage = ImageAdd("Ball.png"); // load the ball image to memory

  BallView  = ViewAdd(BallImage, 0, 0); // put the image in a view at x,y coordinates

}

 

void AppExit()

{

 

}

 

void OnTimer // we could move the ball here by updating its x,y

{

 

}

 

It’s that easy!

 

Animation for a walk sequence might require 20 frames. To do this, load the 20 images calling ImageAdd() 20 times to load each frame of animation and then create only one view using ViewAdd() - because only one of the images in the animation will be  on the screen at any time. Inside OnTimer(), use ViewSetImage() to put the next image into the view and possibly advance the x using ViewSetxy() so that as the walk animates, the character also moves forward.

 

The opposite situation is when you need only one Image but you need it to appear many times. You could load one image, using ImageAdd() and then create 5 views of it by calling ViewAdd() 5 times assigning the same ball image to each view. We only need to load the ball image once, but we need 5 views. Here it is – just change AppMain() as below:

 

int BallImage;

int BallView[5];

 

void AppMain() // the program begins here

{

  int i;

 

   BallImage = ImageAdd("Ball.png"); // load the ball image to memory

 

  for (i = 0; i < 5; i++)

   {

       BallView[i] = ViewAdd(BallImage, i * 20, 0); // put the image in a view at x,y coordinates

   }

}

 

You will want to control each of the views separately so you can make BallView an array if you wish:

 

int BallView[5];

 

Simply assign the ViewAdd result to BallView[i]

 

Now lets go back to a single ball and make it move across the screen.

Here is the complete example code.

 

#include "DragonFireSDK.h"

 

int BallImage;

int BallView;

 

int Ballx; // we need these to keep up with the ball’s x,y location

int Bally;

 

void AppMain() // the program begins here

{

   Ballx = 0; // init x coordinate

   Bally = 0; // init y coordinate

   BallImage = ImageAdd("Ball.png"); // load the ball image to memory

   BallView = ViewAdd(BallImage, Ballx, Bally); // place the image in a view on the screen at x,y coordinates

}

 

void AppExit()

{

 

}

 

void OnTimer() // we could move the ball here by updating its x,y

{

   Ballx += 2; // advance x by 2 pixels each frame

   Bally += 4; // advance y by 4 pixels each frame

   ViewSetxy(BallView, Ballx, Bally);

}