【问题标题】:Sprite Kit detect contactSprite Kit 检测接触
【发布时间】:2014-05-03 10:22:41
【问题描述】:

我有四个 Sprite:Ball、Objects、Line 和 Stars。 我还定义了类别:

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;

属性:

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;

现在在我的didBeginContact 方法中(没关系):

    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];


}

另一部分(这不起作用):

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

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

}

我的错在哪里?我想要:当球“接触”明星时,我得到 100 分。

【问题讨论】:

    标签: ios7 collision-detection sprite-kit


    【解决方案1】:

    您的代码中有错字:(starsCsategory)

    ball.physicsBody.contactTestBitMask = objectsCategory | starsCsategory;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多