O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a game loop and scoring

We have a very nice minigame; now, let us add a game loop and scoring. For the game loop, we will spawn a certain number of objects at different locations, and the player will have to catch the objects. If they catch the object, a point will be added to the score. The final score shown will be the objects caught out of the total objects dropped.

Getting ready

In the MainScene.h file, add the following variables:

#import "cocos2d.h" #import <CoreMotion/CoreMotion.h> @interface MainScene : CCNode <CCPhysicsCollisionDelegate>{ CGSize winSize; CGPoint center; CCPhysicsNode *_physicsWorld; CCSprite *basketSprite; CMMotionManager *_motionManager; CCSprite *wheelSpriteL, *wheelSpriteR; CCPhysicsJoint *motorL; CCPhysicsJoint ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required