Major Xcode 7 Sprite Kit Atlas Bug

2019-02-22 11:49发布

So today I decided to begin testing my game on El Capitan and iOS 9. This is a large project that I have been working on in my spare time for almost 2 years now. So I port my code over to Swift 2.0, click the run button and pray that Apple hasn't broke Sprite Kit (as they have in the past: one, two, three, four and don't even get me started on the shape node...). So my game launches, and what do you know — all of my nodes are mis-positioned, as well as my animated textures. Some other small bugs too such as the draw count not showing up but those are small and hopefully they will be fixed as well.

So I begin debugging and eventually I am able to find that most of the issue is related to the nodes in my atlases not being positioned correctly. So I created a sample project as shown below using just one node. You can see in the picture I set the nodes anchor point to (0,0) and position to (0,0). The scene's anchor point is also (0,0). I printed out all of these values to verify they are correct.

enter image description here

You can also see that it is drawn correctly in the editor. However when I launch the game I get the following:

enter image description here

You can see that the node is drawn incorrectly. It's position is (0,0) yet it is drawn offset. And no my scene is not scaled, it matches the size of the view and is set on ResizeFill.

I get this issue on both El Capitan and iOS 9. What's interesting is that the issue becomes more noticeable the more the image contains transparent pixels. As you can see from the editor screen shot, my image contains many transparent pixels as I wanted to clearly show the bug. If I had used less transparent pixels, the node would have been less offset.

If I don't use an atlas then the node is drawn correctly as shown below. However I obviously want to use atlases so that I can batch render my nodes.

enter image description here

I have filed this bug on Radar. Has anyone found a workaround to this issue that doesn't involve not using atlases?

1条回答
乱世女痞
2楼-- · 2019-02-22 12:00

I have found a workaround to this as I was posting the question. Hopefully this helps other people who encounter the issue. And hopefully Apple fixes this major bug before the final release.

If you use the new XCAssets atlases AND you set the deployment target to the latest version, the node is rendered correctly. So all you have to do is move all of your atlases to the XCAssets. This effects iOS 8/Yosemite backwards compatibility though.

enter image description here

查看更多
登录 后发表回答