////////////Template code //////////// Chunk 2 //Add a fence collision else if(([nameA containsString:@"Fence"] && [nameB containsString:@"Ball"]) || ([nameA containsString:@"Ball"] && [nameB containsString:@"Fence"])){ SKNode *ball; if([nameA containsString:@"Ball"]){ ball = contact.bodyA.node; } else{ ball = contact.bodyB.node; } /* You missed the ball - Game Over */ if(contact.contactPoint.y < 10){ SKAction *actionAudioExplode = [SKAction playSoundFileNamed:@"sound_explode.m4a" waitForCompletion:NO]; NSString *particleExplosionPath = [[NSBundle mainBundle] pathForResource:@"ParticleBall" ofType:@"sks"]; SKEmitterNode *particleExplosion = [NSKeyedUnarchiver unarchiveObjectWithFile:particleExplosionPath]; particleExplosion.position = CGPointMake(0,0); SKAction *actionParticleExplosion = [SKAction runBlock:^{ [ball addChild:particleExplosion]; }]; SKAction *actionRemoveBall = [SKAction removeFromParent]; SKAction *switchScene = [SKAction runBlock:^{ SKView * skView = (SKView *)self.view; [self removeFromParent]; // Create and configure the scene. MyGameOver *scene = [MyGameOver nodeWithFileNamed:@"GameOver"]; scene.scaleMode = SKSceneScaleModeAspectFill; // Present the scene. [skView presentScene:scene]; }]; SKAction *actionExplodeSequence = [SKAction sequence:@[actionParticleExplosion,actionAudioExplode,[SKAction fadeOutWithDuration:0.25],actionRemoveBall,switchScene]]; [ball runAction:actionExplodeSequence]; } else{ SKAction *fenceAudio = [SKAction playSoundFileNamed:@"sound_wall.m4a" waitForCompletion:NO]; [self runAction:fenceAudio]; }