SpriteKit游戏中的帧速率极低



我有一个内置在SpriteKit中的游戏,我偶尔会开发它。我在iOS 8还是iOS的最新版本时就开始开发它了。当时,它总是以每秒60帧或几乎(在物理设备上)的速度运行。然而,从iOS 9到现在的iOS 10,这款游戏在我的iPhone 5上的运行速度只有区区12帧/秒。实际上,它在模拟器上通常运行得更快(13-14fps),这是闻所未闻的。

我用Instruments做了一个分析,似乎有些慢是因为应用程序每帧做两次枚举。它们在这里:

-(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];
}
}];
}

这些枚举会移动起始背景,直到它离开屏幕,然后将其从父项中删除,并在完成后循环常规背景。有更有效的方法吗?此外,有没有其他方法可以在不损失任何质量的情况下优化应用程序?我的图像相对较大(背景为1080x3840),但我不确定是否可以使用较小的图像,然后在不降低质量的情况下升级它们。

感谢您对提高帧速率的任何帮助,如果需要,我可以展示更多代码。

感谢

iOS 8和9之间最大的变化是添加了一个cameranode:

https://developer.apple.com/reference/spritekit/skcameranode

还有臭名昭著的性能下降

苹果论坛上有很多关于iOS 9性能的抱怨。苹果公司没有及时和令人满意地进行沟通。由于缺乏有意义的修复和解释,许多SpriteKit用户和潜在用户都失去了。

在你的情况下,切换到使用相机进行视差可能会恢复一些性能。

以下是正在讨论的一些关于性能的问题,因此您可能会看到是否有人在做类似的事情:

https://forums.developer.apple.com/thread/14487

https://forums.developer.apple.com/thread/30651

最新更新