SpriteKit最大节点数 [英] SpriteKit max number of nodes

查看:130
本文介绍了SpriteKit最大节点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个带有平铺地图的SpriteKit游戏。每个图块都是SKSprite节点。当我有大约800个瓷砖时,没有问题。但是如果我尝试将地图的大小增加到大约2000个区块,我的FPS将从60增加到20.屏幕上的区块节点数量不会改变(大约80),只是屏幕外的节点数量。任何可能导致这种情况的想法,或者如何解决这个问题?

I am creating a SpriteKit game with a tiled map. Each tile is an SKSprite node. When I have about 800 tiles, there are no problems. But if I try to increase the size of the map to around 2000 tiles, my FPS goes from 60 to 20. The number of tile nodes on the screen doesn't change (about 80), just the number of nodes off-screen. Any ideas of what could be causing this, or how to remedy it?

推荐答案

似乎没有最大限度的定义节点数量。这实际上取决于您设备上的可用内存量。例如,请考虑以下代码:

There doesn't appear to be a defined max number of nodes. It really depends on the amount of available free memory on your device. For example consider the following code:

int NODE_LIMIT = 375000
....

    for (int i = 0; i<NODE_LIMIT; i++) {
        SKNode *node = [SKNode node];
        [self addChild:node];
    }

我可以在我的精灵工具包游戏中创建375000个节点。但随着我增加数量,我的设备内存不足。设备上的可用内存量会因许多因素而异。 正如评论中所提到的,帧率降低的原因是因为物理模拟甚至可以在屏幕上看不到的节点上运行。

I can create 375000 nodes in my sprite kit game. But as I increase the number above that, my device runs out of memory. The amount of free memory on your device will vary depending on a number of factors. As mentioned in the comments, the reason your frame rate slows down, is because the physics simulation runs even for nodes which are not visible on screen.

为了保持较高的帧速率,摆脱不可见的物理体,或者不需要每帧模拟的物理体。你可以通过只在它们位于屏幕的可视部分时添加精灵/物理体,并在它们不存在时删除它们来实现。

To maintain a high frame rate, get rid of physics bodies which are not visible, or which do not need to be simulated every frame. You could do this by adding sprites / physics bodies only when they are in the viewable part of the screen, and removing them when they are not.

这篇关于SpriteKit最大节点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆