【发布时间】:2018-11-17 03:43:57
【问题描述】:
我有一个充当游戏菜单页面的场景,并使用 UI 按钮来激活 skaction,该 skaction 在场景中移动相机并使用 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,那么为什么一个会比另一个慢呢?
【问题讨论】:
-
ShowMenu 是做什么的?
-
它告诉父视图将隐藏菜单项的alpha设置为1。
标签: swift sprite-kit