0

When I try using xscale to flip my any of of my SKSpriteNodes around, they stop detecting collisions. I have tried many different ways to fix this, including moving the anchor point, wrapping a container node around all of my nodes, and reiterating the physics body. This third option is the only one i've had any success with, but it won't work in most situations. Is there any way to fix this short of flipping all the artwork and creating a double of every animation atlas?

    self.player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(30, 60)];
    self.player.position= CGPointMake(400, 200);
    self.player.zPosition = 25;
    self.player.physicsBody.dynamic = YES;
    self.player.physicsBody.usesPreciseCollisionDetection = YES;
    self.player.physicsBody.friction = 0;
    self.player.name = @"player";
    self.player.physicsBody.categoryBitMask = player;
    self.player.physicsBody.contactTestBitMask = ground;
    self.player.physicsBody.collisionBitMask = monsterCategory;
    self.player.physicsBody.allowsRotation = false;
    [self addChild:self.player];

   for (UITouch *touch in touches){
    CGPoint touchLocation = [touch locationInNode:self];
    if (touchLocation.x>self.player.position.x &&touchLocation.y>=135) {
        forward2 = YES;
        multiplierForDirection2 = 1;
    }else if (touchLocation.x<self.player.position.x && touchLocation.y>=135){
        reverse2 = YES;
        multiplierForDirection2 = -1;
    }
    if (mode2 ==1) {
        [self walkingBear];
    }else if (mode2 ==2){
        jump2 = true;
        [self fly];
    }else if (mode2 == 3){
        [self weapon];
    }
}
    self.player.xScale = fabs(self.player.xScale)*multiplierForDirection2;

1 Answers1

1

Unfortunately not. Using the command xScale = -1 plays havoc with the sprite's physics body. I tried various approaches to this problem but could not come up with an acceptable fix. The only solution you have, for now at least, is to create mirror images.

To flip each image I used the Preview app and created a keyboard shortcut for the Flip Horizontal command. That made the job much faster.

sangony
  • 11,636
  • 4
  • 39
  • 55