【发布时间】:2015-12-11 22:47:57
【问题描述】:
我在 SpriteKit 中有一个 SkSpriteNodes 的横向滚动平铺背景,并且偶尔会在平铺之间不断出现细小的间隙,因为它们没有准确地相互对接。我使用的代码是这样的;
func updateBackground() {
worldNode.enumerateChildNodesWithName("Background", usingBlock: { node, stop in
if let background = node as? SKSpriteNode {
let scrollAmount = CGPoint(x: -self.kBackgroundSpeed * CGFloat(self.deltaTime), y: 0)
background.position += scrollAmount
if background.position.x < -background.size.width {
background.position += CGPoint(x:background.size.width * CGFloat(self.kNumBackgroundSprites), y: 0)
}
}
})
}
我需要对这段代码做些什么来防止出现空白?
【问题讨论】:
-
您是否尝试过使用
floorf()之类的函数来确保您所有的精灵大小和位置都是像素对齐的?
标签: ios swift sprite-kit tvos