SpriteKit 使用 95-100% CPU when 运行 game with large tilemap (JSTileMap)
SpriteKit using 95-100% CPU when running game with large tilemap (JSTileMap)
我的项目在 iPhone 6 上以 55-60FPS 的速度运行,但任何更旧的项目都完全无法播放,因为有东西在吃 CPU。
我认为问题与我的地图上的图块和层数有关(64x256,4 层),Instruments 显示 "SKCRenderer:preprocessSpriteImp(..." 花费 5198 毫秒 (23.2%) 运行 时间。
JSTileMap 是否一次加载每个图块的图像(可见或不可见)?来自 RW 的 post 表明情况确实如此,并且可以通过解决它来大幅提升性能:
http://www.raywenderlich.com/forums/viewtopic.php?f=29&t=9479
In another performance note - Sprite Kit checks all it's nodes and
decides which ones it needs to display each frame. If you have a big
tile map, this can be a big performance hit. JSTileMap loads all the
nodes (SKSpriteNode for each tile) when it loads the tile map. So, I
was also seeing performance issues in the Sprite Kit version with my
maps (which are 500 x 40 tiles). I added a check to my version of
JSTileMap that's included in the kit that marks the hidden property of
each tile, then intelligently unhides and hides only the tiles that
enter/exit the screen space. That increased performance on these
larger maps significantly.
不幸的是,post 没有详细说明为解决此问题所采取的步骤。
我的第一个想法是(我是初学者,请保持温和)通过遍历每个点并检查特定层上的图块来创建一个节点数组。从那里我会根据与玩家的距离来处理 adding/removing 它们。
这没有用,因为将节点添加到数组的过程只会导致应用程序在较大的地图上永远挂起。
有人可以帮忙吗?我喜欢使用 larger/more 复杂的瓷砖地图,但这个性能问题正在毁掉我的大脑。
感谢阅读!
更新:非常感谢 SKAToolKit: https://github.com/SpriteKitAlliance/SKAToolKit
他们的剔除功能解决了我的问题,我现在 运行 甚至更大的地图不到 35% CPU。
JSTileMap 在处理较大的地图时存在一些问题,但您确实有几个选项需要考虑:
- 将您的大地图分成几个小块并根据需要加载每个新块。
- 只加载玩家附近的对象。
- 只加载玩家附近的方块。
我个人发现无法使用 JSTileMap 完成#3,因为我找不到包含地图图块的数组。我通过使用 SKAToolKit 解决了这个问题,它提供了对地图图块数组的轻松访问。它是解析在 Tiled 中创建的地图的绝佳资源。
我的项目在 iPhone 6 上以 55-60FPS 的速度运行,但任何更旧的项目都完全无法播放,因为有东西在吃 CPU。
我认为问题与我的地图上的图块和层数有关(64x256,4 层),Instruments 显示 "SKCRenderer:preprocessSpriteImp(..." 花费 5198 毫秒 (23.2%) 运行 时间。
JSTileMap 是否一次加载每个图块的图像(可见或不可见)?来自 RW 的 post 表明情况确实如此,并且可以通过解决它来大幅提升性能: http://www.raywenderlich.com/forums/viewtopic.php?f=29&t=9479
In another performance note - Sprite Kit checks all it's nodes and decides which ones it needs to display each frame. If you have a big tile map, this can be a big performance hit. JSTileMap loads all the nodes (SKSpriteNode for each tile) when it loads the tile map. So, I was also seeing performance issues in the Sprite Kit version with my maps (which are 500 x 40 tiles). I added a check to my version of JSTileMap that's included in the kit that marks the hidden property of each tile, then intelligently unhides and hides only the tiles that enter/exit the screen space. That increased performance on these larger maps significantly.
不幸的是,post 没有详细说明为解决此问题所采取的步骤。
我的第一个想法是(我是初学者,请保持温和)通过遍历每个点并检查特定层上的图块来创建一个节点数组。从那里我会根据与玩家的距离来处理 adding/removing 它们。
这没有用,因为将节点添加到数组的过程只会导致应用程序在较大的地图上永远挂起。
有人可以帮忙吗?我喜欢使用 larger/more 复杂的瓷砖地图,但这个性能问题正在毁掉我的大脑。
感谢阅读!
更新:非常感谢 SKAToolKit: https://github.com/SpriteKitAlliance/SKAToolKit
他们的剔除功能解决了我的问题,我现在 运行 甚至更大的地图不到 35% CPU。
JSTileMap 在处理较大的地图时存在一些问题,但您确实有几个选项需要考虑:
- 将您的大地图分成几个小块并根据需要加载每个新块。
- 只加载玩家附近的对象。
- 只加载玩家附近的方块。
我个人发现无法使用 JSTileMap 完成#3,因为我找不到包含地图图块的数组。我通过使用 SKAToolKit 解决了这个问题,它提供了对地图图块数组的轻松访问。它是解析在 Tiled 中创建的地图的绝佳资源。