我在使用Swift 3和Spritekit开发应用程序时遇到了一个问题.为了检测碰撞,我制作了四个独立的三角形组成一个正方形.当我将这些三角形旋转为一个单元时,它们重叠并且在旋转期间不保持正方形的形状(它们彼此重叠),但是一旦旋转完成就会恢复正常.
这是我用于轮换的代码:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let location = touch.location(in: self)
if location.x < 0 {
blueTriLeft.run(SKAction.rotate(byAngle: CGFloat(M_PI_2), duration: 0.2))
redTriLeft.run(SKAction.rotate(byAngle: CGFloat(M_PI_2), duration: 0.2))
yellowTriLeft.run(SKAction.rotate(byAngle: CGFloat(M_PI_2), duration: 0.2))
greenTriLeft.run(SKAction.rotate(byAngle: CGFloat(M_PI_2), duration: 0.2))
} else if location.x > 0 {
blueTriRight.run(SKAction.rotate(byAngle: CGFloat(-M_PI_2), duration: 0.2))
redTriRight.run(SKAction.rotate(byAngle: CGFloat(-M_PI_2), duration: 0.2))
yellowTriRight.run(SKAction.rotate(byAngle: CGFloat(-M_PI_2), duration: 0.2))
greenTriRight.run(SKAction.rotate(byAngle: CGFloat(-M_PI_2), duration: 0.2))
}
}
}
Run Code Online (Sandbox Code Playgroud)
下面是我的广场的图片,由四个独立的三角形组成
请随时向我询问您需要查看的任何其他代码,任何输入都有帮助.此外,我无法在行动中得到重叠的问题,所以提前抱歉,但我会尽力去做.