O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

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

Simulating bullets

Bullets and other fast moving objects are a fundamental part of many video games. In this recipe, we will see how to properly implement bullet physics.

Simulating bullets

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe. Also note that some of the following code has been omitted for brevity.

How to do it...

Execute the following code:

@implementation Ch4_Bullets /* Fire the gun */ -(void) fireGun { //Fire 10 bullets per second if(fireCount > 0){ return; } fireCount = 0.2f; CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache]; //Fire bullet in the correct direction float gunAngle = ...

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