且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SpriteKit SKTexture.preloadTextures 高内存使用 Swift

更新时间:2023-11-17 16:05:22

您应该记住,图像文件大小(在您的示例中为 1Kb)与将相同图像存储在 RAM 中所需的内存量无关.您可以使用以下公式计算所需的内存量:

You should keep in mind that image file size (1Kb in your example) have nothing with amount of memory required for same image to be stored in RAM . You can calculate that amount of memory required with this formula:

宽 x 高 x 每像素字节数 = 内存大小

width x height x bytes per pixel = size in memory

如果您使用标准 RGBA8888 像素格式,这意味着您的图像将需要大约 0.5 兆字节的 RAM 内存,因为 RGBA8888 每个像素使用 4 个字节 - 每个红色、绿色、蓝色各 1 个字节,以及 1 个字节用于 alpha 透明度.您可以阅读更多 这里.

If you using standard RGBA8888 pixel format this means that your image will require about 0.5 megabytes in RAM memory, because RGBA8888 uses 4 bytes per pixel – 1 byte for each red, green, blue, and 1 byte for alpha transparency. You can read more here.

所以你能做的就是优化你的纹理并使用不同的纹理格式.这是另一个关于纹理的例子优化.

So what you can do, is to optimize you textures and use different texture formats. Here is another example about texture optimization.