使用 atlas 文件和 SpriteKit 进行批量绘图的问题 [英] Issues with batch drawing with atlas files and SpriteKit

查看:46
本文介绍了使用 atlas 文件和 SpriteKit 进行批量绘图的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在构建的平台游戏中遇到了延迟问题.所以我正在研究如何提高性能.

So I ran into a problem with lag on a platformer game I'm building. So I'm researching how to improve performance.

我正在尝试进行批量绘制,以减少绘制调用.我有问题.因此,对于一个全新的项目:

I'm trying to do batch drawing, so that there is less draw calls. I'm having issues though. So with a brand new project:

我有 4 个英雄精灵,所有图像都存储在一个 .atlas 文件夹中.所以 atlas 文件夹中的每个精灵都有一个 1/2/3x 的图像.

I have 4 hero sprites, all images are stored in a .atlas folder. so there is a 1/2/3x image for each sprite in the atlas folder.

我将其拖放到 xcassets 文件夹中.然后我去我的 sks 文件创建 4 个精灵并相应地更改纹理.

I drag and drop that into the xcassets folder. Then I go to my sks file create 4 sprites and change the texture accordingly.

默认情况下,它们都具有相同的混合模式.我将默认规则设置为 true 以忽略同级顺序.所有精灵都在默认的 z 0 层上.我把它设置为显示抽奖次数.

By default they all have the same blend mode. I have the default rule set to true for ignoring sibling order. All sprites are on the default z 0 layer. and I have it set to show draw count.

我希望看到 1 个绘制,因为所有图像都在同一个 atlas 文件中,但我看到了 4 个.

I would expect to see 1 draw since all images are in the same atlas file, but I see 4.

有什么我遗漏的吗?

只是好奇我是如何让它正常工作的.感谢您的帮助!!!

Just curious how I get this to work properly. Thanks for any help!!!

推荐答案

iOS 9 上的 xcassets 存在一个错误,即使将图像放置在 xcassets 中也不会减少绘制调用.显然,这在以后的版本中得到了修复,但从那以后我再也没有打扰过 xcassets.相反,我将图像放在项目中单独的 .atlas 文件夹中,这确实减少了绘制调用.

There was a bug with xcassets on iOS 9 where draw calls wouldn't be reduced even if images were placed in xcassets. Apparently that was fixed with later versions, but since then I never bothered with xcassets. Instead I place images in a seperate .atlas folder in the project, which does reduce the draw calls.

尝试放置 4 个具有相同纹理的精灵,然后查看绘制调用是什么.如果精灵使用相同的纹理,它不应该是 4.我还建议添加 8 个精灵(4 个不同的纹理 * 每个精灵 2 个)并查看绘制调用是否增加到 8 个.

Try to place 4 sprites with the same texture and see what the draw calls are then. It shouldn't be 4 if the sprites are using the same texture. I would also suggest to add 8 sprites (4 different textures * 2 sprites each) and see if the draw calls increase to 8.

如果绘制调用不增加,那么我认为绘制 4 个不同的精灵需要 4 个绘制调用(如果它们非常复杂).如果绘制调用确实增加,请尝试从 xcassets 中删除图像并将它们放入项目中单独的 .atlas 文件夹中,然后比较绘制调用.

If the draw calls don't increase, then I would assume that 4 draw calls is what it takes to draw your 4 different sprites (if they are very complex ones). If the draw calls do increase, try removing the images from xcassets and place them into a seperate .atlas folder in your project, and compare draw calls then.

这篇关于使用 atlas 文件和 SpriteKit 进行批量绘图的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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