1
self.player.xScale = fabs(self.player.xScale)*multiplierForDirection2;

当我使用将玩家向左转时,他无法检测到来自enemy2 的碰撞,但可以检测到来自enemy1 的碰撞,即使两者的位掩码相同。我遇到了类似的问题,最终不得不为左移的敌人和右移的敌人创建两个不同的函数。
xScale 究竟在做什么来防止碰撞?

4

1 回答 1

0

I'm assuming this is spriteKit.... If you create a SKNode to act as the parent object of self.player, you can attach the collider to the SKNode and use xScale = -1 on the player. Something like this:

    SKNode *parent = [SKNode new];
    parent.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.player.frame.size];
    [parent addChild:self.player];
    self.player.xScale = -1;

Similar to having an empty game object to hold everything together. Unfortunately, some of your code might have to change to accommodate the new parent node.

于 2014-07-24T17:44:58.647 回答