Reputation: 316
I have a game built in SpriteKit that I occasionally work on. I started working on it when iOS 8 was still the latest version of iOS. Back then, it always ran at 60fps or almost (on a physical device). However, since iOS 9, and now on iOS 10, the game runs at a measly 12fps on my iPhone 5. It actually usually runs faster on the simulator (13 - 14fps), which is unheard of.
I did an analysis with Instruments and it appears that some of the slowness comes from the app doing two enumerations every frame. Here they are:
-(void)moveBackground
{
[self enumerateChildNodesWithName:@"stars" usingBlock:^(SKNode *node, BOOL *stop)
{
SKSpriteNode *bg = (SKSpriteNode *)node;
CGPoint bgVelocity = CGPointMake(0, -150); //The speed at which the background image will move
CGPoint amountToMove = CGPointMultiplyScalar (bgVelocity,0.08);
bg.position = CGPointAdd(bg.position,amountToMove);
if (bg.position.y <= 0)
{
bg.position = CGPointMake(bg.position.x, bg.position.y + bg.size.height/2);
}
}];
[self enumerateChildNodesWithName:@"opbg" usingBlock:^(SKNode *node, BOOL *stop)
{
SKSpriteNode *opbg = (SKSpriteNode *)node;
CGPoint bgVelocity = CGPointMake(0, -150); //The speed at which the background image will move
CGPoint amountToMove = CGPointMultiplyScalar (bgVelocity,0.08);
opbg.position = CGPointAdd(opbg.position,amountToMove);
if (opbg.position.y <= 0)
{
[self.opbg removeFromParent];
}
}];
}
These enumerations move the starting background until it is offscreen, then remove it from the parent, and cycle the regular background once that one is done. Is there a more efficient way of doing this? Additionally, is there another way of optimizing the app without losing any quality? My images are relatively large (background is 1080x3840), but I'm not sure if I can use smaller ones and then upscale them without losing quality.
Any help improving my framerate is appreciated, and I can show more code if needed.
Thanks
Upvotes: 2
Views: 485
Reputation: 6288
The biggest change between iOS 8 and 9 was the addition of a cameranode:
https://developer.apple.com/reference/spritekit/skcameranode
And an infamous amount of performance degradation.
There's a litany of Apple forum complaints about performance on iOS 9. There was no communication from Apple in a timely and satisfactory manner. Many SpriteKit users and potential users were lost as a result of the lack of meaningful fixes and explanations.
In your case, switching to use of the camera to do your parallaxes might regain some performance.
Here's some of the issues regarding performance being discussed, so you might see if anyone was doing something similar:
https://forums.developer.apple.com/thread/14487
https://forums.developer.apple.com/thread/30651
Upvotes: 2