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 and reusing bullets

The logic behind the Bullet class is quite similar to that of the Enemy class. We'll create a bunch of bullets outside of the screen, and use them when needed. If they are activated, that is on screen, we update their position depending on who fired them. Let's do that and have our enemies fire first.

  1. The following should go in the Bullet.h file:
    #import <Foundation/Foundation.h> #import "cocos2d.h" #import "GameScene.h" @class GameLayer; @interface Bullet : CCNode { CCSprite * mySprite; GameLayer * theGame; bool fired; int whoFired; int firingSpeed; } @property (nonatomic,retain) CCSprite * mySprite; @property (nonatomic,retain) GameLayer * theGame; @property (nonatomic,readwrite) bool fired; @property ...

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