views:

71

answers:

1

I am writing a small game by using cocos2d. It is a shooting game. Player on one side and enemy on other side. To run the both actions of player shooting and enemy shooting do we should use threads ? Or can we do without using them. At present I am not using threads. But I can manage to do both actions of player and enemy at same time. Should I use threads compulsory good performance ? Or am I doing wrong without using threads ? Please help me from this confusion. Thank you.

+2  A: 

You should use threads when it makes sense, i.e., when you would otherwise block the main (UI) thread during a time-consuming operation. Examples of expensive operations include loading images and sounds from disk and retrieving information from a network. For the event loop of a game, threads are not essential because the events in a game are not perfectly simultaneous (indeed, two operations are never simultaneous on the iPhone because it is a single-processor system). Instead, you can perform all of your game logic sequentially and update the UI as necessary. If I'm not mistaken, though, a framework like Cocos2D probably uses a dependency inversion model that calls into your client code, and as such it will create any necessary threads behind the scenes. I'd suggest looking at a tutorial on that specific framework to see what the recommended style is.

warrenm