O'Reilly logo

iOS Game Programming Cookbook by Bhanu Birani, Chhavi Vaishnav

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 real-world simulation

Now we will be adding some real simulation in the game. We will add more physics bodies and make them interact with each other. This will help us to understand the physics interaction between various physics objects.

How to do it...

Now we have the infinite bouncing ball in place. To add more fun to the game, let us add some more elements to the it.

  1. First we will add the static block to the game. To accomplish this, add the following line of code at the end of the initWithSize method:
    SKSpriteNode* block = [[SKSpriteNode alloc] initWithImageNamed: @"block.png"]; block.name = paddleCategoryName; block.position = CGPointMake(CGRectGetMidX(self.frame), block.frame.size.height * 0.6f); [self addChild:block]; block.physicsBody ...

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