O'Reilly logo

Cocos2d for iPhone 0.99 Beginner's Guide by Pablo Ruiz

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

Time for action - creating a poly-shaped object

  1. Create a new class and name it Totem.
  2. Replace the Totem.h file's content with the following lines:
    #import <Foundation/Foundation.h>
    #import "cocos2d.h"
    #import "chipmunk.h"
    @class GameLayer;
    @interface Totem : CCNode {
    CCSprite * mySprite;
    cpBody * myBody;
    cpShape * myShape;
    GameLayer * theGame;
    }
    @property (nonatomic,retain) CCSprite * mySprite;
    @property (nonatomic,retain) GameLayer * theGame;
    @property (nonatomic,readwrite) cpBody * myBody;
    @property (nonatomic,readwrite) cpShape * myShape;
    @end
    
  3. Then change the Totem.m file's content to look like the following:
    #import "Totem.h" #import "GameScene.h" @implementation Totem @synthesize mySprite,myBody,myShape,theGame; -(id) initWithPosition:(CGPoint)pos ...

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