Book Image

Mastering Cocos2d Game Development

By : Alex Ogorek
Book Image

Mastering Cocos2d Game Development

By: Alex Ogorek

Overview of this book

Table of Contents (15 chapters)
Mastering Cocos2d Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting a scene up and running


Before we even start adding anything to the screen, we need to make sure we have a game that can be viewed on our device or a simulator. Once you've created the project in SpriteBuilder (or gotten the blank project that was listed earlier) and opened the project in Xcode, go to the next step.

Creating the initial code for the scene to open

You should see a file called MainScene.h and another file called MainScene.m. Open the header file (which has the .h extension).

In the header file, add a few lines of code between the @interface line and the @end line. The header should look like this:

@interface MainScene : CCNode
{
  CGSize winSize;
}
+(CCScene*)scene;
@end

Then, in the main file (which has the .m extension), some lines of code should be added between the @implementation and @end lines. It should look as follows:

#import "MainScene.h"

@implementation MainScene

+(CCScene *)scene
{
  return [[self alloc] init];
}

-(id)init
{
  if ((self=[super init]))
  {
...