在我将 iPhone 升级到 ios 7.1 后,didBeginContact 方法永远不会被调用。谁知道怎么修它?
我们有
在 MainScene.h
@interface MainScene : SKScene <SKPhysicsContactDelegate>
在 MainScene.m 中
-(id)initWithSize:(CGSize)size
{
[self.physicsWorld setGravity:CGVectorMake(0, kGravity)];
[self.physicsWorld setContactDelegate:self];
_ground.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_ground.size];
[_ground.physicsBody setCategoryBitMask:kGroundCategory];
[_ground.physicsBody setCollisionBitMask:kPlayerCategory];
[_ground.physicsBody setAffectedByGravity:NO];
[_ground.physicsBody setDynamic:NO];
_player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(_player.size.width * kHitAreaScale, _player.size.height * kHitAreaScale)];
[_player.physicsBody setDensity:kDensity];
[_player.physicsBody setAllowsRotation:NO];
[_player.physicsBody setCategoryBitMask:kPlayerCategory];
[_player.physicsBody setContactTestBitMask: kGroundCategory | kMonsterCategory kTopFloorCategory];
[_player.physicsBody setCollisionBitMask:kGroundCategory | kMonsterCategory | kTopFloorCategory];
}
The following code in MainScene.m never get called in ios 7.1
- (void)didBeginContact:(SKPhysicsContact *)contact
{
// firstBody: player
SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask)
{
firstBody = contact.bodyA;
secondBody = contact.bodyB;
}
else
{
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
}