IwGame Engine Tutorial – The Game

CIwGame Object – The Eye in the Sky

Introduction

CIwGame is basically the kind of eye-in-the-sky controller of the game engine and can be thought of as the main loop of the game engine. CIwGame takes care of many things including:

  • Initialisation, processing and clean-up of many systems including graphics, input, resource manager and audio etc..
  • Managing and updating scenes
  • Sorting scenes by layer order
  • Notifying the user of scene change events
  • Rendering scenes
  • Tracking frame speed
  • Processing events such as tapped, touch begin / end

You never actually create an instance of CIwGame, instead you derive you own version of the class from CIwGame like this:

#define	GAME	Game::getInstance()

class Game : public CIwGame
{
	CDEFINE_SINGLETON(Game)
public:
protected:
	//// Properties
public:
	//// Properties end
protected:
public:
	void			Init(bool enable_http);
	void			Release();
	bool			Update();
	void			Draw();
	void			PostDraw();
	void			Save();
	void			Load();
};

You then implement Init(), Release(), Update() and Draw() methods to provide your own initialisation, clean-up, per frame update and per frame rendering code. You can also override PostDraw() to apply post rendering.

Note that the games Init() method takes a parameter called enable_http. If you plan on using anything relating to the HTTP manager, such as ads, web file / image access then you will need to pass true to the game object during initialisation.

Implementing our own CIwGame

Lets now take a quick look at a bare bones implementation of the above methods:

CDECLARE_SINGLETON(Game)

void Game::Init(bool enable_http)
{
	CIwGame::Init(enable_http);

	// TODO: Insert your own initialisation here
}

void Game::Release()
{
	// TODO: Insert your own cleanup here

	CIwGame::Release();
}

bool Game::Update()
{
	if (!CIwGame::Update())
		return false;

	// TODO: Insert your own custom game update functionality here

	return true;
}

void Game::Draw()
{
	CIwGame::Draw();

	// TODO: Insert your own custom game rendering functionality here
}

void Game::Save()
{
	// TODO: Insert your own game save functionality
}

void Game::Load()
{
	// TODO: Insert your own game load functionality
}

Note that if you utilise IwGames systems then it is very unlikely that you will need to add additional rendering code to Game::Draw().

At its heart, CIwGame contains a collection of game scenes (CIwGameScene’s) that in turn drive actors and cameras to provide your games functionality (more on these classes later).

CIwGame enables you to add, remove and search for scenes within the game as well as set the currently active scene using the following methods:

void		addScene(CIwGameScene *scene, bool bring_to_front = true);
void		removeScene(CIwGameScene* scene);
void		removeScene(unsigned int name_hash);
CIwGameScene*	findScene(unsigned int name_hash);
CIwGameScene*	findScene(const char* name);
CIwGameScene*	findScene(int type);
CIwGameScene*	getScene(int index);
void		clearScenes();
void		changeScene(CIwGameScene *new_scene);
bool		changeScene(unsigned int name_hash);
CIwGameScene*	getCurrentScene();
void		BringSceneToFront(CIwGameScene* scene);

Note that all visible scenes will be rendered every game frame and usually only the current scene will be updated.

4 thoughts on “IwGame Engine Tutorial – The Game

  1. sara says:

    Hi dr.mop

    I’m beginning to marmalade and I want first to only render My animated

    character without writing any code for user input interaction but the

    problem that I faced is “assertion failure”
    the problem is as follow :

    IwAssert failure (UTIL, 1642).
    Message: 408 out of uint8 range, casting to 152

    CIwTextParser error: \models/male.mtl, line 5

    Callstack:
    CIwTextParserITX::ReadIntArray
    CIwMaterial::ParseAttribute
    _ITXReadUnknown
    CIwTextParser::_Parse
    CIwTextParser::ParseString
    CIwTextParser::ParseFile
    CIwTextParserITX::ParseFile
    CIwResHandlerGEO::Build
    CIwResManager::LoadRes
    CIwResGroup::ParseAttribute
    _ITXReadUnknown
    CIwTextParser::_Parse
    CIwTextParser::ParseString
    CIwTextParser::ParseFile
    CIwTextParserITX::ParseFile
    CIwResManager::LoadGroup
    IwGxInit

    when press ignore all the memory problem come as follow:

    Debug Heap out of memory. Allocating 2384280 bytes but only 89840

    available (78172 LFB). Increase icf setting [s3e] MemSizeDebug (current

    value is 5242880).

    do not what is my problem ,can you Mr.mop help me in knowing my error.

    Thanks in advance,

  2. drmop says:

    You do not have enough memory reserved for your app. The memory error says that you are attempting to allocate 2384280 bytes but only 89840 are available. Try increasing the amount of memory available to your app by editing the app.icf file that is located in your data folder and add the following:

    [S3E]
    MemSize=20485760

    This should give you around 20MB of memory to use, you can always increase or decrease this value to match your needs.

  3. sara says:

    I edit the memory size but still there is problem in assertions do not know what it is !!

    also this message appear:

    Memory exception (11) attempting to access: 00205128 [ip=048F83F0]

    “before and after editing” when I press ‘continue’ button in memory problem messege.

    what is usually the reasons of “IwAssert failure (UTIL, 1642).”

    please dr.mop help me ,and if you can give me your email becouse I have gradution project and I want ask about some points in marmalade I faced them during writing the code.

    Thanks so much,

  4. drmop says:

    I’m afraid I’ve not seen that type of assertion before. Although the error message “Message: 408 out of uint8 range, casting to 152” seems to suggest that you are using data that does not fit inside an 8 bit number. You would be better off asking on the Marmalade support forums as these issues relate to Marmalade SDK and not the IwGame Engine – http://www.madewithmarmalade.com/devnet/forum

Leave a Reply