【问题标题】:Xscale is preventing collision detectionXscale 正在阻止碰撞检测
【发布时间】:2014-04-17 05:08:19
【问题描述】:

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

    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;

【问题讨论】:

    标签: collision-detection sprite-kit xscale


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 2014-08-12
      • 1970-01-01
      • 2011-09-05
      相关资源
      最近更新 更多