Here is a little demo I’ve made. It’s an animated sprite which you move with the D-Pad. Pressing A+B causes the animation to pause. Then you can advance or rewind frames by pressing A and B respectively. By pressing both, the animation is resumed. I coded the sprite bitmap manually after designing it in Paint.NET. Please tell me what you think.
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
const byte platformGuy_frame1[] PROGMEM = {8,10,
B00111110,
B01001010,
B01000001,
B00100110,
B00111100,
B00101000,
B00111000,
B00101000,
B00100100,
B00111100};
const byte platformGuy_frame2[] PROGMEM = {8,10,
B00111110,
B01001010,
B01000001,
B00100110,
B00111100,
B00110111,
B00111101,
B01011001,
B01001111,
B01111000};
const byte platformGuy_frame3[] PROGMEM = {8,10,
B00111110,
B01001010,
B01000001,
B00100110,
B00111100,
B00110100,
B11111100,
B10010100,
B10110010,
B11111110};
const byte* const platformGuy_spritesheet[] PROGMEM =
{
platformGuy_frame1,
platformGuy_frame2,
platformGuy_frame3
};
void setup()
{
gb.begin();
gb.titleScreen(F("myBitmap"));
}
uint8_t bmp_x=LCDWIDTH/2;
uint8_t bmp_y=LCDHEIGHT/2;
uint8_t frame_counter=0;
uint8_t frame_last=2;
uint8_t anim_timer=0;
uint8_t anim_speed=4;
bool anim_run=true;
void loop()
{
if(gb.update())
{
if(gb.buttons.repeat(BTN_RIGHT,1))
{
bmp_x++;
}
if(gb.buttons.repeat(BTN_LEFT,1))
{
bmp_x--;
}
if(gb.buttons.repeat(BTN_UP,1))
{
bmp_y--;
}
if(gb.buttons.repeat(BTN_DOWN,1))
{
bmp_y++;
}
if(anim_run)
{
if(gb.buttons.repeat(BTN_A,1))
{
if(gb.buttons.pressed(BTN_B))
{
anim_run=false;
}
}
if(gb.buttons.repeat(BTN_B,1))
{
if(gb.buttons.pressed(BTN_A))
{
anim_run=false;
}
}
if(anim_run)
{
if(++anim_timer>=anim_speed)
{
if(frame_counter++==frame_last)
{
frame_counter=0;
}
anim_timer=0;
}
}
}
else
{
if(gb.buttons.pressed(BTN_A))
{
if(frame_counter++==frame_last){frame_counter=0;}
}
if(gb.buttons.pressed(BTN_B))
{
if(frame_counter--==0){frame_counter=frame_last;}
}
if(gb.buttons.repeat(BTN_A,1))
{
if(gb.buttons.pressed(BTN_B))
{
anim_run=true;
}
}
if(gb.buttons.repeat(BTN_B,1))
{
if(gb.buttons.pressed(BTN_A))
{
anim_run=true;
}
}
}
gb.display.drawBitmap(bmp_x, bmp_y, (byte*)pgm_read_word(&platformGuy_spritesheet[frame_counter]));
if(gb.buttons.pressed(BTN_C))
{
gb.titleScreen(F("myBitmap"));
}
}
}