////////////Template code //////////// Chunk 3 //Add blocks // Add blocks SKSpriteNode *node = [SKSpriteNode spriteNodeWithImageNamed:@"block.png"]; CGFloat kBlockWidth = node.size.width; CGFloat kBlockHeight = node.size.height; CGFloat kBlockHorizSpace = 20.0f; int kBlocksPerRow = (self.size.width / (kBlockWidth+kBlockHorizSpace)); //Top row of blocks for (int i = 0; i < kBlocksPerRow; i++) { node = [SKSpriteNode spriteNodeWithImageNamed:@"block.png"]; node.name = @"Block"; node.position = CGPointMake(kBlockHorizSpace/2 + kBlockWidth/2 + i*(kBlockWidth)+i*kBlockHorizSpace, self.size.height - 100.0); node.zPosition = 1; node.lightingBitMask = 0x1; node.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:node.size center:CGPointMake(0, 0)]; node.physicsBody.dynamic = NO; node.physicsBody.friction = 0.0; node.physicsBody.restitution = 1.0; node.physicsBody.linearDamping = 0.0; node.physicsBody.angularDamping = 0.0; node.physicsBody.allowsRotation = NO; node.physicsBody.mass = 1.0; node.physicsBody.velocity = CGVectorMake(0.0, 0.0); node.physicsBody.contactTestBitMask = 0x01; node.physicsBody.usesPreciseCollisionDetection = NO; [self addChild:node]; } // Middle row of blocks kBlocksPerRow = (self.size.width / (kBlockWidth+kBlockHorizSpace)) - 1; for (int i = 0; i < kBlocksPerRow; i++) { node = [SKSpriteNode spriteNodeWithImageNamed:@"block.png"]; node.name = @"Block"; node.position = CGPointMake(kBlockHorizSpace + kBlockWidth + i*(kBlockWidth)+i*kBlockHorizSpace, self.size.height - 100.0 - (2.0 * kBlockHeight)); node.zPosition = 1; node.lightingBitMask = 0x1; node.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:node.size center:CGPointMake(0, 0)]; node.physicsBody.dynamic = NO; node.physicsBody.friction = 0.0; node.physicsBody.restitution = 1.0; node.physicsBody.linearDamping = 0.0; node.physicsBody.angularDamping = 0.0; node.physicsBody.allowsRotation = NO; node.physicsBody.mass = 1.0; node.physicsBody.velocity = CGVectorMake(0.0, 0.0); node.physicsBody.contactTestBitMask = 0x01; node.physicsBody.usesPreciseCollisionDetection = NO; [self addChild:node]; } /* Third row of blocks */ kBlocksPerRow = (self.size.width / (kBlockWidth+kBlockHorizSpace)); for (int i = 0; i < kBlocksPerRow; i++) { node = [SKSpriteNode spriteNodeWithImageNamed:@"block.png"]; node.name = @"Block"; node.position = CGPointMake(kBlockHorizSpace/2 + kBlockWidth/2 + i*(kBlockWidth)+i*kBlockHorizSpace, self.size.height - 100.0 - (4.0 * kBlockHeight)); node.zPosition = 1; node.lightingBitMask = 0x1; node.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:node.size center:CGPointMake(0, 0)]; node.physicsBody.dynamic = NO; node.physicsBody.friction = 0.0; node.physicsBody.restitution = 1.0; node.physicsBody.linearDamping = 0.0; node.physicsBody.angularDamping = 0.0; node.physicsBody.allowsRotation = NO; node.physicsBody.mass = 1.0; node.physicsBody.velocity = CGVectorMake(0.0, 0.0); node.physicsBody.contactTestBitMask = 0x01; node.physicsBody.usesPreciseCollisionDetection = NO; [self addChild:node]; }