2010年6月23日 星期三

[IPhone] iphone game develop concept

If we want to develop game on iphone, we must use iphone sdk to control iphone device, see this figure 1.(Reference from Iphone game development)

Game is a state machine, user input data can change state, game state depend on game logic.
Example:
User touch panel to move game role to touch point.



if(role location != touch location)
{
role move to touch location;
}

if(role location == touch location)
{
role stand at touch location;
}


Figure 1.


But I think that user input data is from iphone device(touch panel).


Figure 2.


When implement a game, we will use a Main Loop to update game logic and render game screen. Use HandleEvent to implement user input, update to change game scene and role state, render to update game screen.


void main()
{
while(GAME_PLAY)
{
HandleEvent();
Update();
Render();
}
}


Figure 3.



In my CloudBox, I use UIView and UIImageView to implement game, so my render function is invalid. I use draw to addSubView once.


void main()
{
Draw();
while(GAME_PLAY)
{
HandleEvent();
Update();
//Render();
}
}


Figure 4.

沒有留言:

張貼留言

Hello