How do sprites work?
How do sprites work?
Well actually, pretty much everything you see on Ringo is clear code.
Backgrounds, simple shapes, and individual pixels are being drawn directly to the screen and everything else that is a little bit more complex is located in one very specific file called sprites.c.
Every icon and image is actually converted in pure code that corresponds with RGB565 bitmap, but more on that a little bit later.
There any many different ways the colors are defined digitally. Probably the most popular encoding is RGB, which actually means RED, GREEN, and BLUE. Every color is represented by the mix of those three colors. RGB565 uses a total of 16 bits to code one specific color. 5 bits are used for both red and blue values, while 6 bits are used for the green value. All in all, those 16 bits are represented with a 4-digit hexadecimal number since one hex digit is 4 binary digits. For example, code 0xF800 is translated to RGB(128,0,0) which would translate to clean red. This way of coding is much more memory efficient than RGB888, which uses 8 bits of information for each color, and it still allows for a huge array of different colors.
Additionally, there are some simple black icons, that are just represented by 0s and 1s. If the pixel should be black it's set to 1 and if not it's set to 0. These types of sprites are much simpler and take up much less memory, so don't use colored ones unless you have to.
Well, these are the necessary steps:
- Draw the bitmap inside of a graphic editor
- Convert the bitmap to RGB565 code
- Save that code to sprites.c (or one of the files)
- Draw the bitmap on the display