0

当我尝试使用 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;
4

1 回答 1

1

不幸的是没有。使用该命令xScale = -1会对精灵的物理体造成严重破坏。我尝试了各种方法来解决这个问题,但无法提出可接受的解决方案。至少目前,您拥有的唯一解决方案是创建镜像。

为了翻转每个图像,我使用了预览应用程序并为水平翻转命令创建了键盘快捷键。这使工作变得更快。

于 2014-04-17T12:56:41.310 回答