![]()
这是我用于轮换的代码:
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)) } }} 下面是我的广场的图片,由四个独立的三角形组成
请随时向我询问您需要查看的任何其他代码,任何输入都有帮助.此外,我无法在行动中得到重叠的问题,所以提前抱歉,但我会尽力去做.
解决方法 问题是你正在旋转单个三角形,它们会根据自己的坐标系进行旋转.想象一下,每个三角形都固定在中心,并围绕它旋转.显然三角形将重叠.您应该围绕一个独特的点旋转它们.在您的情况下,最简单的方法是将它们添加到同一父节点,然后旋转父节点:// This is the configuration to do in sceneDIDLoadlet node = SKNode()node.addChild(blueTrileft) node.addChild(redTrileft)node.addChild(yellowTrileft)node.addChild(greenTrileft)scene.addChild(node)// InsIDe touchesBegan(_:,with:)node.run(SKAction.rotate(byAngle: CGfloat(-M_PI_2),duration: 0.2))总结
以上是内存溢出为你收集整理的ios – 作为一个单元旋转时重叠的SpriteNodes全部内容,希望文章能够帮你解决ios – 作为一个单元旋转时重叠的SpriteNodes所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)