Search code examples
iosxcodesprite-kitalphalag

One image with alpha lagging spritekit


I am making a game, and it involves a sandstorm. I decided that the basic concept would be that I would make an image that looks roughly like a sandstorm, and then decorate it with some particles/whatever else it takes.

I ran into an issue at step one. I threw together a simple image for testing purposes: Poorly Made Sandstorm

I added that to my game, and the FPS dropped by 60%. I was surprised by the effect one image had, but I wasn't too worried about it. I cut the resolution of the image in half, and again, lots of lag.

Is spritekit/iOS really that bad at handling moderately sized images with alpha? I read on another question that the simulator is bad at rendering, but that can't be the entire problem.

Is there any hope for getting this to render without slicing my performance? The particles work well, everything else runs at 60fps just fine, but the addition of this image is apparently a severe drain on resources.

EDIT: I tested my game out on my phone, and I got no lag. So apparently, the simulator is just really bad at rendering after all. At the same time, I am curious as to how to speed up performance, as there is clearly some kind of lag going on.


Solution

  • I'm no expert on SpriteKit, but I had similar experiences with plain core animation and layering.

    The issue is that an image with alpha, even for the "opaque" parts of it, it introduces a redrawing call on all the sublayers underneath it for every time it moves. First check if this is actually the problem, and then, try one of this, and see if it improves:

    1. SKCropNode could prevent for rendering the underneath elements
    2. Tile the image so only the border has alpha
    3. Snapshot the underneath layers.
    4. Reduce the amount of nodes being rendered, hide the ones that are "under the sandstorm".

    And you should be using real devices to test performance of your game, you cannot rely on the simulator for that.