I need to have an animation as big as the iPad retina screen, 2048x1536, but that size exceed the maximum size, is there any other way I can make an animation that big? I already tried using some sprites and SKActions to achieve the same results but I wanted to switch to SKTextureAtlas for performance reasons
-
A working example can be seen in this fire demo: http://stackoverflow.com/a/38679128/763355 – MoDJ Dec 15 '16 at 21:04
1 Answers
Let's forget the fact that you can't use that big images and assume that you use a bit smaller images (eg. 2000x1500 which will work). What are downsides of this ?
Memory consumption
An image with size 2000x1500 can take as little as 20 kilobytes or even less when stored on disk, but this has nothing to do with actual memory consumption when the same image is loaded into memory. To calculate the required RAM for a standard RGBA8888 image, you can use this:
width x height x bytes per pixel = size in memory
RGBA8888 format uses 4 bytes for each pixel (1 byte for each red, green, blue and alpha channel) If you do the math, you will see that each of your 2048x1536 image will require approximately 12 megabytes in memory. Obviously because the memory is not unlimited resource, you can easily run into memory issues.
Batch rendering and a draw calls
Another, more important thing is there is no real benefit of putting this big images into an atlas, and SpriteKit will split an atlas if necessary. For example, in the case of ten 2000x1500 images, SpriteKit will split an atlas texture into ten atlas textures. This will require 10 draw calls when rendering and the whole purpose of using atlases is beaten.
Solution
If you really need that big animation, use a video instead of images. This is recommended by Apple in the SKVideoNode section:
Like any other node, you can put the movie node anywhere inside the node tree and Sprite Kit will render it properly. For example, you might use a video node to animate some visual behaviors that would be expensive to define using a collection of textures.
Or you can try to make an animation in a different way eg. to remove the static parts from animation, and animate what really needs to be animated. Also you can try to break an animation into few parts.
-
Hey, thanks for your answer, I am experiencing performance problem with my game (maybe due to my bad code, I don't know), so I'm trying to reduce the number of sprites, the SKTextureAtlas would be 37 images, do you think it is better to use 4 more sprites than an animation that big? – Carlo Blasi Jan 19 '16 at 20:32
-
@carlb In general, SpriteKit is able to render hundreds of sprites at 60fps, if draw calls are kept to low. But this is a whole another topic, so you should ask a new question with relevant info like (current draw calls, node count, iOS, device you are testing on etc). That way, somebody will probably see where the problem is, and will give you the optimal solution, but as I said, you have to provide a lot more data than this. – Whirlwind Jan 19 '16 at 21:10
-
You are going to be better off making Nodes and coding up your animation, a H264 file will not render as large as the whole ipad screen in all iPad 3 and 4 hardware. You could use huge PNGs, but app size would be a real problem. Better to use a smaller video and scale it up or build the animation with Nodes. – MoDJ Jul 31 '16 at 22:30