Game Development Reference
In-Depth Information
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 follow-
ing 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 a physics body to it and
change the various parameters of the physics body object as well. The most im-
portant thing to note here is block.physicsBody.dynamic = NO . By de-
fault all the physics bodies are dynamic; so to create static bodies, we just need to
set the physicsBody.dynamic Boolean to NO .
2. After adding the code, the final file should look something similar to the following
screenshot:
Search WWH ::




Custom Search