Question

I have four Sprites: Ball, Objects, Line and Stars. I defined also categories:

static const uint32_t ballCategory = 0x1 << 0; static const uint32_t objectsCategory = 0x1 << 1; static const uint32_t lineCategory = 0x1 << 2; static const uint32_t starsCategory = 0x1 << 3;

properties:

ball.physicsBody.categoryBitMask = ballCategory;
ball.physicsBody.contactTestBitMask = objectsCategory | starsCsategory;
object.physicsBody.categoryBitMask = objectsCategory;
object.physicsBody.contactTestBitMask = ballCategory;
star.physicsBody.categoryBitMask = starsCategory;
star.physicsBody.contactTestBitMask = ballCategory;
line.physicsBody.categoryBitMask = lineCategory;
line.physicsBody.contactTestBitMask = objectsCategory;

now in my didBeginContact method (thats ok) :

    if( ( contact.bodyA.categoryBitMask & lineCategory ) == lineCategory || ( contact.bodyB.categoryBitMask & lineCategory ) == lineCategory ) {

    score++;
    scoreLabelNode.text = [NSString stringWithFormat:@"%ld", (long)score];

}
    if( ( contact.bodyA.categoryBitMask & ballCategory ) == ballCategory || ( contact.bodyB.categoryBitMask & ballCategory ) == ballCategory ) {

    [self gameOver];


}

the other part ( this not works):

if( ( contact.bodyA.categoryBitMask & starsCategory ) == starsCategory || ( contact.bodyB.categoryBitMask & starsCategory ) == starsCategory ) {

    score = score + 100;
    scoreLabelNode.text = [NSString stringWithFormat:@"%ld", (long)score];

}

Where is my fault? I want: when the ball "contact" the star, i get 100 points.

Was it helpful?

Solution

You have a typo in your code: (starsCsategory)

ball.physicsBody.contactTestBitMask = objectsCategory | starsCsategory;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top