从sks文件滚动SKReferenceNodes

时间:2015-07-02 20:49:01

标签: ios swift sprite-kit

我想滚动使用我在界面构建器中放在一起的sks文件创建的SKReferenceNodes。我之前已经滚动了SKSpriteNodes,我正在尝试使用相同的代码,但我的SKReferenceNodes似乎没有框架,所以我无法定位它们。

以下是我的SKReferenceNode设置:

let BG_POINTS_PER_SEC = 50
var dt:NSTimeInterval = 0
let background1 = SKReferenceNode(fileNamed:"BackgroundScene1")
let background2 = SKReferenceNode(fileNamed:"BackgroundScene2")
在didMoveToView中

background1.position = CGPointZero;
background2.position = CGPointMake(background1.frame.size.width, 0)

self.addChild(background1)
self.addChild(background2)
更新中的

moveBackground()

func moveBackground() {
  let bgVelocity = CGPoint(x:-BG_POINTS_PER_SEC, y:0)
  let amtToMove = bgVelocity *CGFloat(dt)
  background1.position = background1.position + amtToMove
  background2.position = background2.position + amtToMove
  if (background1.position.x <= background1.frame.size.width) {
   background1.position.x = CGPointMake(background2.position.x + background2.frame.size.width, background1.position.y)
  }
  if (background2.position.x <= background2.frame.size.width) {
   background2.position.x = CGPointMake(background1.position.x + background1.frame.size.width, background2.position.y)
  }
}

同样,这适用于使用SKSpriteNode滚动背景,但SKReferenceNode返回0帧。这甚至可以从像这样的sks文件中滚动SKReferenceNodes吗?

0 个答案:

没有答案