Major Bug, Sprite Atlas created in XCAssets Folder does not support batch rendering

随声附和 提交于 2019-12-18 17:03:05

问题


I started using the new Sprite Atlas in the XCAssets folder instead of having my atlases in the project folder. However I noticed that when I did this my nodes were no longer being batch rendered which resulted in a large number of inefficient draw calls. This completely defeats the purpose of using an atlas!

To be clear this is the code I used to get the atlas.

let atlas = SKTextureAtlas(named: "Sprites")

"Sprites" is a Sprite Atlas created in the XCAssets Folder.

Does anyone have a workaround or am I stuck making Sprite Kit Atlases in the project folder.

I'm using Xcode 7.2 beta.

The reason why I want to use the new Sprite Kit Atlases is because of this issue.


回答1:


I found one workaround as I was typing the question. You can create a SKTextureAtlas programmatically from images inside the XCAssets folder like so:

let atlas = SKTextureAtlas(dictionary: ["Head":UIImage(named: "Head")!, "Body":UIImage(named: "Body")!])

This is obviously just a workaround. Hopefully Apple fixes this in later versions of Sprite Kit. This is a pretty serious performance bug that all developers should be aware of. Even Apple's sample project uses the new Sprite Atlases so you think they would have batch rendering working.

Update 1 Response from Apple:

Thanks for letting us know about this issue. We are currently investigating the cause, and will be incorporating a fix in future iOS updates. In the mean time, there are two workarounds you can apply: 1. Create and use texture atlas in a .atlas folder. 2. Continuing using texture atlas in the asset catalog, but with deployment target set to iOS 8.0.

Update 2 Apple said may have been fixed in iOS 10. Going to investigate.




回答2:


This appears to be fixed in iOS 10. The only annoying thing is that you can't have two images that have the same name even if they are in separate atlases.

Edit: this is only fixed in iOS 10. If you're running in iOS 9, there's a massive memory leak that will crash the app.



来源:https://stackoverflow.com/questions/33976783/major-bug-sprite-atlas-created-in-xcassets-folder-does-not-support-batch-render

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!