Sprite set: delete specific node instead of all nodes

I created an application that has a constant stream of "stone" nodes falling from the sky in two different sizes. The player controls the third stone object and receives points depending on which of the two types of falling stone is going to. Finally, the beam object functions like moving earth. So far, I have added conflict detection in my application, which detects collisions between different stones and a beam. This is my collision code:

static const uint32_t stoneCategory = 1;
static const uint32_t beamCategory = 2;
static const uint32_t stoneCategory2 = 4;

and

-(void)didBeginContact:(SKPhysicsContact *)contact{

SKPhysicsBody *firstBody;
SKPhysicsBody *secondBody;

CGPoint contactPoint = contact.contactPoint;

float contact_x = contactPoint.x;
float contact_y = contactPoint.y;

if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask)
{
     firstBody = contact.bodyA;
     secondBody = contact.bodyB;
}

else
{
    firstBody = contact.bodyB;
    secondBody = contact.bodyA;
}


// First condition: make big stone stick to moving beams 
if ((firstBody.categoryBitMask & stoneCategory) != 0)
{
    SKPhysicsJointFixed *joint =
    [SKPhysicsJointFixed jointWithBodyA:contact.bodyA
                                  bodyB:contact.bodyB
                                 anchor:CGPointMake(contact_x, contact_y)];

    [self.physicsWorld addJoint:joint];
}


// Second condition: remove small stone on collision with big stone

if ((firstBody.categoryBitMask & stoneCategory) != 0 &&
    (secondBody.categoryBitMask & stoneCategory2) != 0)
{

      NSLog(@"Hit");

      [self enumerateChildNodesWithName:@"stone" usingBlock:^(SKNode *node, BOOL *stop) {
      [node removeFromParent];
  }];
}

, . , . , , . : , , , ( "" ), , , .

, . : node, ? , , , .

:

-(void) addStone
 {

 SKSpriteNode *stone = [[SKSpriteNode alloc] initWithColor:[SKColor grayColor] size:CGSizeMake(12, 12)];

stone.position = CGPointMake(skRand(0, self.size.width), self.size.height+12);
stone.name = @"stone";
stone.physicsBody.categoryBitMask = stoneCategory2;
stone.physicsBody.contactTestBitMask = stoneCategory;

stone.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:stone.size];
stone.physicsBody.usesPreciseCollisionDetection = YES;

[self addChild:stone];
}

createSceneContents

SKAction *makeStone= [SKAction sequence:@[
                                        [SKAction performSelector:@selector(addStone) onTarget:self],
                                        [SKAction waitForDuration:0.30 withRange:0.25]
                                        ]];

 [self runAction:[SKAction repeatActionForever:makeStone]];

. , .

+3
3

 1) z ,

so when you remove a small stone at first time and recreate it changes its body from A to B

 if(([contact.bodyA.node.name isEqualToString:@"bigstone"] && [contact.bodyB.node.name isEqualToString:@"smallstone"] ) || ([contact.bodyA.node.name isEqualToString:@"smallstone"] && [contact.bodyB.node.name isEqualToString:@"bigstone"]) )
        {


            if([contact.bodyA.node.name isEqualToString:@"smallstone"] )
            {
                [contact.bodyA.node removeFromParent];
            }else{
                [contact.bodyB.node removeFromParent];
            }

    }
+4

[self enumerateChildNodesWithName:@"stone" usingBlock:^(SKNode *node, BOOL *stop) {
            [node removeFromParent];
        }];
+1
if ((firstBody.categoryBitMask & stoneCategory) != 0 &&
    (secondBody.categoryBitMask & stoneCategory2) != 0)
{
      NSLog(@"Hit");
      [secondBody.node removeFromParent];
}
0
source

All Articles