I've been experimenting with SKLightNode
in SpriteKit (new in iOS8) and, even in a really simple test case, I've been getting terrible performance. For instance, with a single light source on a solid color SKSpriteNode
I get 13.2 FPS on a 3rd generation iPad. If I add a second light source, it drops to an abysmal 7.7 FPS.
The WWDC session video What's New in SpriteKit mentions that you might get less than 60 FPS if you have more than one light on the same sprite, but I can't even get 60 FPS with one. Here's the relevant section.
Here's my test scene in swift (it starts with one light source and more can be added by tapping):
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
let center = CGPointMake(size.width / 2.0, size.height / 2.0)
let background = SKSpriteNode(color: SKColor.lightGrayColor(), size: size)
background.position = center
background.lightingBitMask = 1
addChild(background)
let light = SKLightNode()
light.position = center
light.falloff = 1.0
light.lightColor = SKColor(hue: 0.62 , saturation: 0.89, brightness: 1.0, alpha: 0.4)
light.shadowColor = SKColor.blackColor().colorWithAlphaComponent(0.4)
addChild(light)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let light = SKLightNode()
light.position = location
light.falloff = 1.0
light.lightColor = SKColor(hue: 0.62 , saturation: 0.89, brightness: 1.0, alpha: 0.4)
light.shadowColor = SKColor.blackColor().colorWithAlphaComponent(0.4)
addChild(light)
}
}
}
Here are some screen shots of it running on my 3rd gen iPad:
And here's what the performance tab looks like after clicking the "Analyze" button when it's running with a single light source:
It's obviously GPU bound, but what I'm trying to figure out is if I'm just doing something horribly wrong, or if this is just an issue with the beta that will (hopefully) be cleared up by release time. I'm currently using Xcode6-Beta5.
UPDATE
I upgraded my iPhone 5S to iOS8 and tried the same thing there and it ran perfectly fine at 60FPS with 8 light sources. So, I guess this is just an issue with the 3rd generation iPad's GPU just not being up to the task. I'll try again after the next beta is released and see if anything changes, just in case.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…