我有一个场景,它充当游戏的菜单页面,并使用UI按钮来激活滑移动作,从而在场景上移动相机并使用UIView容器更改菜单按钮。
该代码只是将摄像机从最左边移动到最右边。以完全相同的速度。但是由于某种原因,向右的运动要比向左的运动慢?
func MoveCameraToRight () {
let CameraWidth = StartingWidth * SceneCamera.xScale
let MoveRight = SKAction.move(to: CGPoint(x: (scene?.frame.maxX)!-(CameraWidth/2), y: (camera?.position.y)!), duration: 1)
camera?.run(MoveRight)
}
func MoveCameraToLeft () {
let CameraWidth = StartingWidth * SceneCamera.xScale
let MoveLeft = SKAction.move(to: CGPoint(x: (scene?.frame.minX)!-(CameraWidth/2), y: (camera?.position.y)!), duration: 1)
camera?.run(MoveLeft)
}
如您所见,持续时间完全相同。但是由于某种原因,在iPhone XS Max上,它似乎比向左移动要慢得多?
以下是使这些操作运行的代码:
@IBAction func Openlevels () {
let Game = (self.view as! SKView).scene as! MainMenuScene
Game.MoveCameraToRight()
LevelsContainer.isHidden = false
}
func HideLevels () {
let Game = (self.view as! SKView).scene as! MainMenuScene
Game.MoveCameraToLeft()
UIView.animate(withDuration: 0.25, animations: {
self.LevelsContainer.alpha = 0
}) { (complete: Bool) in
self.LevelsContainer.isHidden = true
}
}
然后在容器视图上关闭(并将相机移回左侧):
@IBAction func Home () {
let Parent = self.parent as! MainMenu
Parent.HideLevels()
Parent.ShowMenu()
}
摄像机位置的两个SKAction都设置为1,那么为什么一个慢于另一个?
答案 0 :(得分:0)
解决方案实际上非常简单:
let MoveLeft = SKAction.move(to: CGPoint(x: (scene?.frame.minX)!-(CameraWidth/2), y: (camera?.position.y)!), duration: 1)
向左移动应该是min + camWidth / 2,而不是负。问题是它告诉相机走得比向右移动的距离远。
let MoveRight = SKAction.move(to: CGPoint(x: (scene?.frame.maxX)!-(CameraWidth/2), y: (camera?.position.y)!), duration: 1)