Drawing Sprites

Now that we have converted our cat bitmap into its raw bytes and created a BM_Sprite container that holds information about our cat sprite, the next step is to draw it on the screen.

Creating the Draw Function

All of the graphics that are present in the scene are drawn via the draw function. The active controller will call the current scene's draw function where graphics are writen to a frame buffer before being rendered onto the screen. Let's create our draw function in BM_Scene_CatPad.c after BM_Scene_CatPad_init():

//  BM_Scene_CatPad.c
#include "BM_Scene_CatPad.h"

//  --snip--

//  Draw function (after init)
void BM_Scene_CatPad_draw()
{
    //  First, draw a blank background
    BM_RE_drawLightBackground();

    //  Draw the cat
    BM_RE_drawSprite(   _catSprite.currentBitmap,
                        _catSprite.currentMask,
                        _catSprite.currentXPos,
                        _catSprite.currentYPos,
                        _catSprite.width,
                        _catSprite.height
                    );
}

That's it!
First, we create a fresh canvas by calling BM_RE_drawLightBackground. Then we draw our cat using BM_RE_drawSprite. The _catSprite instance already contains information needed by the function parameters so we pass in the structure's relevant members (currentBitmap, currentXPos etc) into the function.

We would now have a cat that appears on the screen but it does not do much of anything right now. We want to be able top move the cat around the screen as we press the D-pad buttons so our next step is to write code that will handle button press events.