I\'m working on a sprite-kit game where nodes spawn below the lowest point on the screen and gravity is set to have them float to the top of the screen. Everything works per
I would recommend using the built in contact detection in spritekit. Create a skspritenode mimicking a roof that has a physics body set to detect contact with bubbles. Create an event on contact between the roof node and bubble node that will simply remove the bubbles. This will ensure that bubbles are removed and you maintain a constant FPS.
Example of event called on contact:
- (void)bubble:(SKSpritenode*)bubble didCollideWithRoof:(SKSpriteNode*)roof{
[bubble removeFromParent];}
Contact detection example:
- (void)didBeginContact:(SKPhysicsContact *)contact
{
SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask)
{
firstBody = contact.bodyA;
secondBody = contact.bodyB;
}
else
{
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if (firstBody.categoryBitMask==bubbleCategory && secondBody.categoryBitMask == roofCategory)
{
[self bubble:(SKSpriteNode*)firstBody.node didCollideWithRoof:(SKSpriteNode*)secondBody.node];
}}
Bubble needs:
_bubble.physicsBody.contactTestBitMask = roofCategory;
Roof:
SKSpriteNode *roof = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(self.scene.size.width, 1)];
roof.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(self.scene.size.width, 1)];
roof.position = CGPointMake(self.scene.size.width/2,self.scene.size.height)
roof.physicsBody.dynamic = NO;
roof.physicsBody.categoryBitMask = floorCategory;
roof.physicsBody.contactTestBitMask = bubbleCategory;
[self addChild:roof];