没有为powerup令牌调用didbegincontact - 其他spritenode工作正常。例如玩家(飞机)联系直升机工作正常。玩家(飞机)联系加电令牌,没有任何事情发生(没有与之关联)。我已经将面罩更换为与直升机相同但仍然不起作用。节点类别掩码的数量是否有限制?几天后我一直坚持这一点。
//zpositions
float playerZ = .08;
float enemyZ = .08;
float explosionZ = .08;
float tokenz = .08;
//category bit masks
#define playermask 1
#define enemymask 2
#define bulletmask 3
#define tokenmask 9
//add plane
SKSpriteNode *plane = [SKSpriteNode spriteNodeWithImageNamed:@"jet"];
plane.position = CGPointMake(160, 80);
plane.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:plane.size];
//plane.size = CGSizeMake(15,25);
plane.physicsBody.dynamic = NO;
plane.physicsBody.affectedByGravity = NO;
//collision configuration - need to fine tune later
plane.physicsBody.categoryBitMask = playermask;
plane.physicsBody.collisionBitMask = playermask | enemymask | tokenmask;
plane.physicsBody.contactTestBitMask = playermask;
plane.physicsBody.usesPreciseCollisionDetection = YES;
[self addChild:plane];
plane.zPosition = playerZ;
player = plane;
self.physicsWorld.gravity = CGVectorMake(0.0, 0.0);
self.physicsWorld.contactDelegate = self;
//////// TESTING TESTING TESTING ----- Delete After
[self powerUp];
temp.position = CGPointMake(160, 160);
SKAction *makeHelis = [SKAction sequence:@[[SKAction waitForDuration:1.50 withRange:0.35],
[SKAction performSelector:@selector(helicopterEnemies) onTarget:self]]];
[self runAction: [SKAction repeatActionForever:makeHelis]];
//method call for spawning power up tokens
SKAction *makeTokens = [SKAction sequence:@[[SKAction waitForDuration:25.50 withRange:0.35],
[SKAction performSelector:@selector(powerUp) onTarget:self]]];
[self runAction: [SKAction repeatActionForever:makeTokens]];
- (SKSpriteNode*)helicopterEnemies
{
//Helicopter setup
SKSpriteNode *heli = [SKSpriteNode spriteNodeWithImageNamed:@"heli"];
heli.size = CGSizeMake(18,18);
heli.position = CGPointMake(skRand(100, 250),
self.size.height-50);
heli.name = @"helicopter";
heli.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:heli.size];
//need to work on these numbers to coordinate with the other sprites
heli.physicsBody.categoryBitMask = enemymask;
heli.physicsBody.collisionBitMask = enemymask | bulletmask;
heli.physicsBody.contactTestBitMask = bulletmask;
heli.physicsBody.usesPreciseCollisionDetection = YES;
heli.physicsBody.dynamic = YES;
heli.physicsBody.affectedByGravity = NO;
//useless except to show you could change this
//heli.physicsBody.affectedByGravity = YES;
[self addChild:heli];
SKAction *moveDownThenDie = [SKAction sequence:@[
[SKAction waitForDuration:0.10 withRange:0.35],
[SKAction moveByX:0.0 y:-1600 duration:25],
[SKAction removeFromParent]]];
heli.zPosition = enemyZ;
[heli runAction: moveDownThenDie];
return heli;
}
- (SKSpriteNode*)powerUp
{
//Power token setup
SKSpriteNode *powerToken = [SKSpriteNode spriteNodeWithImageNamed:@"powerup"];
//powerToken.size = CGSizeMake(18,18);
powerToken.position = CGPointMake(skRand(100, 250),
self.size.height-50);
powerToken.name = @"Token";
powerToken.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:powerToken.size];
//need to work on these numbers to coordinate with the other sprites
powerToken.physicsBody.categoryBitMask = tokenmask;
powerToken.physicsBody.collisionBitMask = tokenmask | playermask;
powerToken.physicsBody.contactTestBitMask = playermask;
powerToken.physicsBody.usesPreciseCollisionDetection = YES;
powerToken.physicsBody.dynamic = NO;
powerToken.physicsBody.affectedByGravity = NO;
[self addChild:powerToken];
SKAction *moveDownThenDie = [SKAction sequence:@[
[SKAction waitForDuration:0.10 withRange:0.35],
[SKAction moveByX:0.0 y:-1600 duration:25],
[SKAction removeFromParent]]];
powerToken.zPosition = tokenz;
[powerToken runAction: moveDownThenDie];
temp = powerToken;
return powerToken;
}
答案 0 :(得分:0)
找到我的问题的答案...加电令牌对象的动态设置为NO。这会禁用spritekit检查此对象的冲突检测。
powerToken.physicsBody.dynamic = NO;