Now that we know how to create bodies and manage collisions, let's implement a snooker game.
Let's start at the beginning, so replace the contents of GameScene.h
with the following lines:
#import <Foundation/Foundation.h> #import "cocos2d.h" @interface GameScene : CCScene <CCPhysicsCollisionDelegate> { } + (GameScene *)scene; - (id)init; @end
This is the default content of a header file, but in addition we are declaring GameScene
as the delegate of the CCPhysicsCollisionDelegate
protocol in the same way we did in previous sections.
Then we replace the contents of GameScene.m
with the following lines:
#import "GameScene.h" @implementation GameScene { // Declare global variable for screen size CGSize _screenSize; // Declare the physics space CCPhysicsNode *_space; } + (GameScene *)scene { return [[self alloc] init]; }
To get started, we declare the screen size variable and the space of the physics world. The scene
method...