Book Image

Cocos2d for iPhone 0.99 Beginner's Guide

By : Pablo Ruiz
Book Image

Cocos2d for iPhone 0.99 Beginner's Guide

By: Pablo Ruiz

Overview of this book

<p>Cocos2d for iPhone is a robust but simple-to-use 2D game framework for iPhone. If you are just starting with game programming, cocos2d will enable you to make your first game in no time. Even if you are a seasoned game developer, you will still be able to benefit from what it offers. Yet beginning with cocos2d for iPhone may be an arduous task without a proper guide.</p> <p><i>Cocos2d for iPhone 0.99 Beginner</i>&rsquo;s Guide will help you to learn how to make games with cocos2d from the ground up. You will learn all the key concepts of the framework and game programming in general while building your first game using this exciting platform.</p> <p>You will start by learning the basics of cocos2d then you will learn how to enhance your game with a lot of cool features and eye candy. After spending a little time learning the basics, you will jump straight into action. The book will then teach you to build games from scratch and how to add animations, sounds, and particle effects to them. Then you will be guided to have your game behave as in real life by using a physics engine. After reading <i>Cocos2d for iPhone 0.99 Beginner's Guide</i>, you will be able to write your own games for iPhone while using all the elements Pros use. There are a lot of examples, images, and diagrams to get you up to speed in no time.</p>
Table of Contents (18 chapters)
Cocos2d for iPhone 0.99 Beginner's Guide
Credits
About the Author
About the Reviewers
Preface
Index

Managing the game with the CCDirector


The CCDirector is the class whose main purpose is scene management. It is responsible for switching scenes, setting the desired FPS, the device orientation, and a lot of other things.

The CCDirector is the class responsible for initializing OpenGL ES.

Note

If you grab an older Cocos2d project you might notice that all Cocos2d classes have the "CC" prefix missing. Those were added recently to avoid naming problems. Objective-c doesn't have the concept of namespaces, so if Apple at some point decided to create a Director class, those would collide.

Types of CCDirectors

There are currently four types of directors; for most applications, you will want to use the default one:

  • NSTimer Director: It triggers the main loop from an NSTimer object. It is the slowest of the Directors, but it integrates well with UIKit objects. You can also customize the update interval from 1 to 60.

  • Mainloop Director: It triggers the main loop from a custom main loop. It is faster than the NSTimer Director, but it does not integrate well with UIKit objects, and its interval update can't be customized.

  • ThreadMainLoop Director: It has the same advantages and limitations as the Mainloop Director. When using this type of Director, the main loop is triggered from a thread, but it will be executed on the main thread.

  • DisplayLink Director: This type of Director is only available in OS 3.1+. This is the one used by default. It is faster than the NSTimer Director and integrates well with UIKit objects. The interval update can be set to 1/60, 1/30, or 1/15.

Those are the available Directors, most of the times you will not need to make any changes here.