【发布时间】:2017-12-20 15:22:49
【问题描述】:
我有一个使用 Spritekit 永远重复背景的简单代码,我希望背景在任何触摸发生之前保持静止,并且只有在任何触摸开始时才开始动画或滚动
*// animate the background*
let background = SKTexture(imageNamed: "bg.png")
let moveTheBackground = SKAction.move(by: CGVector(dx: -
background.size().width, dy:0), duration: 10)
let backgroundToOriginalPosition = SKAction.move(by: CGVector(dx:
background.size().width, dy: 0), duration: 0)
let animateTheBackground =
SKAction.repeatForever(SKAction.sequence([moveTheBackground,
backgroundToOriginalPosition]))
*// loop the background animation*
var i:CGFloat = 0
while i < 2 {
bg = SKSpriteNode(texture: background)
bg.position = CGPoint(x: background.size().width * i, y: self.frame.midY)
bg.size.height = self.frame.height
bg.zPosition = -1
bg.run(animateTheBackground)
self.addChild(bg)
i += 1
}
我希望在 SpriteKit 中开始触摸时发生此代码, 任何帮助将不胜感激
【问题讨论】:
标签: swift background sprite-kit horizontal-scrolling touchesbegan