我有一个功能,可以在一个向外发射的圆圈中从玩家那里制造8个子弹。我认为问题出在这一行:
let endPoint = CGPoint(x: distance * cos(angle), y: distance * sin(angle))
这导致子弹在圆圈的左下方比右上角的子弹移动得更快,实际上它们应该以相同的速度移动相同的距离。
有谁知道如何实现这个?
func fireSpecialWeapon() {
stride(from: 0, to: 2 * CGFloat.pi, by: 2 * CGFloat.pi / 8 ).forEach { angle in
let bullet = SKSpriteNode(imageNamed: "bulletCircle")
bullet.setScale(3)
bullet.zRotation = angle
bullet.position = player.position
bullet.zPosition = 2
//move outwards to the edge of the screen
let distance: CGFloat = 1000
let endPoint = CGPoint(x: distance * cos(angle), y: distance * sin(angle))
let move = SKAction.move(to: endPoint, duration: 2)
self.addChild(bullet)
bullet.run(move)
}
}
答案 0 :(得分:2)
如果子弹从左下方向右上方移动得更快,则意味着你的锚点(0,0)不是(0.5,0.5)