How to detect contact SKSpriteNode but not react?

I have two first SKSpriteNode heroes

+(id)hero
{
    NSMutableArray *walkFrames = [NSMutableArray array];
    SKTextureAtlas *heroAnimatedAtlas = [SKTextureAtlas atlasNamed:@"HeroImages"];
    int numImages = (int)heroAnimatedAtlas.textureNames.count;
    for (int i=1; i <= numImages; i++) {
        NSString *textureName = [NSString stringWithFormat:@"hero%d", i];
        SKTexture *temp = [heroAnimatedAtlas textureNamed:textureName];
        [walkFrames addObject:temp];
    }
    Hero *hero = [Hero spriteNodeWithTexture:walkFrames[0]];
    hero.heroWalkingFrames = walkFrames;
    hero.name =@"Hero";
    hero.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:hero.size];
    hero.physicsBody.categoryBitMask = heroCategory;
    hero.physicsBody.categoryBitMask = obstacleCategory | groundCategory | homeCategory | ~goodiesCategory;

    return hero;
}

      

and the second is Coin

SKSpriteNode *coin = [SKSpriteNode spriteNodeWithImageNamed:@"coin"];
    coin.size =  CGSizeMake(10,10);
    coin.position = CGPointMake(100,100);
    coin.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:coin.size];
    coin.physicsBody.contactTestBitMask = coinCategory;
    coin.physicsBody.dynamic=NO;
    coin.name = @"coin";

    [self.world addChild:coin];

      

And I can get collision detection with

if([contact.bodyA.node.name  isEqual: @"coin"] || [contact.bodyB.node.name  isEqual: @"coin"])
    {
        //[self LevelComplete];
        SKNode* coinNode ;
        if ([contact.bodyA.node.name  isEqual: @"coin"]) {
            coinNode=contact.bodyA.node;
        }
        else{
            coinNode=contact.bodyB.node;
        }

        [coinNode removeFromParent];
        NSLog(@"Coin touched");
    }

      

Now my problem is that every time the hero jumps and touches the coin, he will descend to the ground, instead, to continue jumping and reach the height it should be, I know I am missing something. but not sure what it is, so anyone can show me the right direction to fix this effect.

+3


source to share


1 answer


Create an additional "nilCategory" and set the collisionBitMask of your coin ..



coin.physicsBody.collisionBitMask = nilCategory;

      

0


source







All Articles