【发布时间】:2018-02-26 13:14:02
【问题描述】:
我希望在 Sprite Kit 中有一个可滚动的背景。我尝试了一些在线提供的other 解决方案,但它们实现了无限滚动背景,我无法根据我的需要调整代码。
这里有一些示例代码,我必须尝试让背景移动(没有检测到到达背景的尽头) - 但它非常不稳定而且一点也不平滑。
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touchLocation = touches.first?.location(in: self), let node = nodes(at: touchLocation).first {
if node.name != nil {
if node.name == "background" {
background.position = touchLocation
}
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touchLocation = touches.first?.location(in: self), let node = nodes(at: touchLocation).first {
if node.name != nil {
if node.name == "background" {
background.position = touchLocation
}
}
}
}
下图展示了我想要实现的目标 - 我希望代码能够检测到您何时到达背景的尽头,并阻止您进一步移动它。
【问题讨论】:
-
创建一个有限宽度的 UIScrollView。它会限制你进一步滚动。
-
创建一个实际的有限场景怎么样?
-
不要创建 UIScrollView,你在 SpriteKit 中工作,而不是 UIKit。你所需要的只是界限,
if bgposition. x < minimumbackground then bgposition.x = minimumbackground
标签: ios swift sprite-kit