当我尝试使用 xscale 翻转我的任何 SKSpriteNodes 时,它们会停止检测碰撞。我尝试了许多不同的方法来解决这个问题,包括移动锚点、将容器节点包裹在我的所有节点周围,以及重复物理体。这第三个选项是我唯一成功的选项,但它在大多数情况下都行不通。有什么办法可以解决翻转所有艺术品并创建每个动画图集的双倍的问题吗?
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;