How to make sprite animations with SDL2?
In this tutorial we makes sprite animations from a sprite sheet with SDL_gpu and SDL2. After that we can start loading the sequences for the animations. Each sprite is an 50 x 37 images. We fill an array of region with each images and then create the sequence from that.
When do you use a sprite sheet for animation?
Animation Animation is the process of drawing similar images in a sequence to simulate some action like walking. Usually, we use the word, ‘frame’ for each sprite being rendered in an animation. Sprite sheets are very commonly used for animation in 2D.
How many pixels are in a sprite sheet?
This image is 128 pixels wide and 64 pixels high. It consists of 4 sub-images (called sprites or frames ), each 32 pixels wide. If we can rapidly render each image in quick succession, just like a cartoon, then we have an animation!
Do you need to tell SDL which part of texture to render?
We need to tell SDL which part of texture is to be rendered on the screen which is possible through Texture Rectangle. If we don’t tell that to SDL, SDL will render the whole texture and fit it to the window rectangle (the first rectangle that we discussed in the previous post).
Is there a texture atlas layer in SDL2?
SDL2 doesn’t itself offer a texture atlas abstraction layer which is perhaps what you meant. It’s your job to know that a particular frame of a sprite animation is at a certain location within a texture.
Are there any non SDL methods for Sprite batching?
An abstraction can be built that lets you operate on a SubTexture that encodes its SDL_Texture and source rect and your SpriteBatch can work from there. My (non-SDL) sprite batching class has methods something like:
Is there draw call batching in SDL2?
The SDL backends can already do draw call batching if they wish to (nothing requires that the Copy command be executed immediately; the only requirement is that it be executed by the time any side effects are required, such as by the end of a Present or if you try to read from the destination or if render/blend state is changed).