【发布时间】:2015-03-13 00:22:53
【问题描述】:
我正在制作一个游戏,我想让我的背景无限地垂直滚动,但我不知道如何开始。我对编码和精灵套件非常陌生,尤其是所以任何帮助将不胜感激。
有人知道我该怎么做吗?
【问题讨论】:
标签: ios objective-c xcode scroll sprite-kit
我正在制作一个游戏,我想让我的背景无限地垂直滚动,但我不知道如何开始。我对编码和精灵套件非常陌生,尤其是所以任何帮助将不胜感激。
有人知道我该怎么做吗?
【问题讨论】:
标签: ios objective-c xcode scroll sprite-kit
您希望有两个节点,一个开始,一个跟随它。最后,永远循环。
func createGroundForward() {
let groundTexture = SKTexture(imageNamed: "Track")
for i in 0 ... 1 {
let ground = SKSpriteNode(texture: groundTexture)
ground.zPosition = -4
ground.position = CGPoint(x: 0, y: -groundTexture.size().height + (groundTexture.size().height + (groundTexture.size().height * CGFloat(i))))
addChild(ground)
let moveLeft = SKAction.moveBy(x:0 , y: -groundTexture.size().height, duration: 5)
let moveReset = SKAction.moveBy(x:0 , y: groundTexture.size().height, duration: 0)
let moveLoop = SKAction.sequence([moveLeft, moveReset])
let moveForever = SKAction.repeatForever(moveLoop)
ground.run(moveForever)
}
}
然后将该函数添加到您的 didMove 函数(类似于 Sprite 的 viewDidLoad)。
override func didMove(to view: SKView) {
self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
createGroundForward()
}
【讨论】:
我会在概念上给你一个答案,给你一个起点,因为你没有提供任何代码。
您将需要多个与屏幕大小相同的图像,并将它们垂直堆叠在一起。
然后您希望将这些图像逐点向下移动。当其中一个图像的顶部到达屏幕底部时,将其放回图像堆栈的顶部。这将导致您的背景无休止地滚动。
祝你好运!
【讨论】: