0
votes

After I upgraded my iPhone to ios 7.1, didBeginContact method never get called. Anyone know how to fix it?

We have

In MainScene.h

@interface MainScene : SKScene <SKPhysicsContactDelegate>

In 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;
    }
}
3
You will need to give us more than that. Some code relating to your implementation is needed. Also, have you tried other devices?ZeMoon
Thanks for your reply. Just added some code in original post.user1377686
try using NSLog within the contact delegate to check whether it is called at all. Also, set a contactTestBitMask on your ground node as well. Did u try other devices?ZeMoon
I found out the problem. I have player xScale set to -1.0. Do you know how to fix it if I want to keep xScale = -1?user1377686
You can easily test if the issue is related to iOS 7.1 by running the same version of your app once in iOS 7.1 Simulator and again in iOS 7.0 Simulator.LearnCocos2D

3 Answers

1
votes

Definitely an xScale problem, Doesn't seem to matter if the xScale is set before or after the physics body is set. As long as the xScale is set to -1 my collisions won't work. xScale of 1 works normal.

0
votes

I had X/Yscale problem after iOS 7.1, maybe this answer also fixes yours.

Just set the physicsBody before X/Yscale.

0
votes

I encountered this problem only yesterday. I wanted to invert the sprite based on it's movement (right or left) and found that setting xScale disables any collisions/contacts.

However, I used this line every time I set the xScale property and everything went back to normal.

node.physicsBody = node.physicsBody;