我有四个精灵:球,物体,线和星星。 我还定义了类别:
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];
}
我的错在哪里?我想:当球&#34;联系&#34;这个明星,我得到100分。
答案 0 :(得分:0)
您的代码中有拼写错误:(starsCategory)
ball.physicsBody.contactTestBitMask = objectsCategory | starsCsategory;