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.
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.
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 = [SKPhysicsBody bodyWithRectangleOfSize:block.frame.size]; block.physicsBody.restitution = 0.1f; block.physicsBody.friction = 0.4f; // make physicsBody static block.physicsBody.dynamic = NO;
First we create the block sprite. After that we associate...