5

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.

Community
  • 1
  • 1
Epic Byte
  • 33,840
  • 12
  • 45
  • 93
  • Is this bug related only to Xcode 7.2 beta & El Captain ? I got it working on Yosemite, Xcode 7.1.1 and iOS 9.1. – Whirlwind Dec 13 '15 at 17:28
  • @Whirlwind I was using beta, but I recall the problem occurring in a previous version as well, not sure which one. What was your deployment target set to when testing? – Epic Byte Dec 13 '15 at 20:28
  • My deployment target was set to 9.1 in this particular case. – Whirlwind Dec 13 '15 at 21:07
  • I apologize...My deployment target was set as 8.1 and it works like that. If I switch deployment target to >= 9 nodes aren't rendered in batches anymore... – Whirlwind Mar 02 '16 at 13:56
  • 1
    @Whirlwind Yea it's a really annoying bug. I've been trying to get my game out for almost 3 years now. I always end up stopping the project when I hit a Sprite Kit bug. I've been fighting Sprite Kit since it's first update in 7.1. It's a shame. I use to look forward to the new additions to Sprite kit, now I just hope they don't touch anything, or at least fix the bugs. And the bugs aren't just with Sprite kit. Game Center multiplayer has been so buggy as well with 4 player real time games. I've probably spend more time finding and reporting bugs to apple then working on my game. – Epic Byte Mar 02 '16 at 14:06

2 Answers2

4

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.

Epic Byte
  • 33,840
  • 12
  • 45
  • 93
  • @claassenApps Not sure, haven't had the pleasure of working with Sprite Kit in awhile. Going to start again after the semester ends. I'll update all of my Sprite Kit bug posts for iOS 10 when I do. If you get the chance to test this feel free to post your findings here. – Epic Byte Nov 07 '16 at 21:12
1

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.

claassenApps
  • 1,137
  • 7
  • 14