gpt4 book ai didi

ios - SpriteKit 在运行带有大型 tilemap (JSTileMap) 的游戏时使用 95-100% CPU

转载 作者:搜寻专家 更新时间:2023-10-31 08:05:13 25 4
gpt4 key购买 nike

我的项目在 iPhone 6 上以 55-60FPS 的速度运行,但任何旧版本都完全无法播放,因为某些东西正在占用 CPU。

我认为问题与 map 上的图 block 和层数有关(64x256,4 层),Instruments 显示“SKCRenderer:preprocessSpriteImp(...”运行时间为 5198 毫秒 (23.2%)。

JSTileMap 是否一次加载每个图 block 的图像(可见或不可见)? RW 的这篇文章表明情况确实如此,并且可以通过解决它来大幅提升性能: 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.

不幸的是,该帖子没有详细说明为解决此问题所采取的步骤。

我的第一个想法是(我是初学者,请保持温和)通过遍历每个点并检查特定层上的图 block 来创建一个节点数组。从那里我会根据与玩家的距离添加/删除它们。

这没有用,因为向数组添加节点的过程只会导致应用在较大的 map 上永远挂起。

有人可以帮忙吗?我喜欢使用更大/更复杂的图 block map ,但这个性能问题正在毁掉我的大脑。

感谢阅读!

更新:非常感谢 SKAToolKit: https://github.com/SpriteKitAlliance/SKAToolKit

他们的剔除功能解决了我的问题,我现在可以用不到 35% 的 CPU 运行更大的 map 。

最佳答案

JSTileMap 在处理较大的 map 时会遇到一些问题,但您确实有几个选项需要考虑:

  1. 将您的大 map 分成几个小块,并根据需要加载每个新 block 。
  2. 只加载玩家附近的那些对象。
  3. 只加载玩家附近的那些图 block 。

我个人发现无法使用 JSTileMap 完成#3,因为我找不到包含 map 图 block 的数组。我使用 SKAToolKit 解决了这个问题它提供了对 map 图 block 阵列的轻松访问。它是解析在 Tiled 中创建的 map 的绝佳资源。

关于ios - SpriteKit 在运行带有大型 tilemap (JSTileMap) 的游戏时使用 95-100% CPU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30749955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com