我有一个塔精灵,周围有一个SKShapeNode,还有一个monsterSprite。怪物精灵受重力影响,所以我可以检测到与TowerSprite的SKShapeNode和monsterSprite的接触。
这是TowerSprites SKShapeNode,我为怪物做了类似的事情(但动态为是):
self.towerRangeNode.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:100];
self.towerRangeNode.physicsBody.dynamic = NO;
self.towerRangeNode.physicsBody.categoryBitMask = PhysicsCatagoryTower;
self.towerRangeNode.physicsBody.collisionBitMask = 0;
self.towerRangeNode.physicsBody.contactTestBitMask = PhysicsCatagoryMonster | PhysicsCatagoryTower;
self.towerRangeNode.physicsBody.usesPreciseCollisionDetection = YES;
然后当我添加怪物时,我会遵循这样的路径:
// creates path to monster to follow
CGMutablePathRef monsterPath = CGPathCreateMutable();
CGPathMoveToPoint(monsterPath, NULL, 0, 0);
CGPathAddLineToPoint(monsterPath, NULL, 310, 0);
CGPathAddLineToPoint(monsterPath, NULL, 310, -65);
CGPathAddLineToPoint(monsterPath, NULL, 12, -65);
CGPathAddLineToPoint(monsterPath, NULL, 12, -130);
CGPathAddLineToPoint(monsterPath, NULL, 350, -130);
SKAction *path = [SKAction followPath:monsterPath asOffset:YES orientToPath:NO duration:15];
[monster runAction:path];
所以我期望发生的是,怪物沿着路径移动,如果它与塔的SkShapeNode碰撞,那么我会收到通知,但是怪物刚从屏幕上掉下来,并且没有。跟随路径,但是如果skShapenode处于其下降路径中,它仍会检测到它。
我希望它能让怪物沿着路径移动,同时能够检测到与SkShapeNodes的接触,而不仅仅是从屏幕上掉下来
感谢