2

I'm using quite large SpriteNodes to move my background (among things) in iOS Swift.

let runningBar = SKSpriteNode(imageNamed: "Bar")
self.addChild(self.scoreText)

It moves like this:

override func update(currentTime: NSTimeInterval) {

    // Golf
    updateRunningBarPosition()

}

func updateRunningBarPosition() {
    runningBar.position.y = CGFloat(Double(runningBar.position.y) + createSinWave(angle) * 1)
    self.angle += 0.01
}

This causes a frame rate drop from 60 fps to about 28-32.

How do I prevent this from happening?

Nick Groeneveld
  • 895
  • 6
  • 18

1 Answers1

2

If the image resources are very large you need to consider the time they will take to upload onto the gpu and render, if they have alpha, or any other effects are applied to them, and you have quite a few images gpu times can grow exponentially and you will end up experiencing frame drops. A good strategy would be to ask yourself if you really need such big images to begin with, as you could break down the work in smaller, easier to process chunks by say, tiling your background, or using stretchable gradients, or break down the big image into 4-10 smaller blocks.

Danny Bravo
  • 4,534
  • 1
  • 25
  • 43