Hmm, I went back and added all the frames I wanted to animate (4 frames in total) into one array and changed the masking to a separate array (but only used one of the masking frames because theyre all the same size). The sprite seems to be masked just fine, but still having trouble with the animation. Here is my current code:
// See: https://mlxxxp.github.io/documents/Arduino/libraries/Arduboy2/Doxygen/html/
#include <Arduboy2.h>
Arduboy2 arduboy;
Sprites player;
int playerx;
int playery;
int crashedshipx;
int crashedshipy;
int shiplandedx;
int shiplandedy;
const byte background [] PROGMEM =
{0x08, 0x00, 0x01, 0x00, 0x02, 0x80, 0x40, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00,
0x50, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const byte shiplanded [] PROGMEM =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x06, 0x20,
0x00, 0x00, 0x00, 0x0C, 0x10, 0x00, 0x00, 0x00,
0x7F, 0xFF, 0xFF, 0xC0, 0x00, 0x40, 0x00, 0x00,
0xFF, 0xC0, 0x47, 0xF8, 0x07, 0xFF, 0xFF, 0x4F,
0xFF, 0xC7, 0xFF, 0xFF, 0x4F, 0xFF, 0xC3, 0xFF,
0xFF, 0x47, 0xF8, 0x01, 0xFF, 0xE0, 0x40, 0x00,
0x00, 0xFF, 0xC0, 0x7F, 0xFF, 0xFF, 0xC0, 0x00,
0x10, 0x00, 0x02, 0x00, 0x00, 0x14, 0x00, 0x01,
0x40, 0x00, 0x38, 0x00, 0x03, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};
const byte crashedship [] PROGMEM =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x00, 0x00, 0x00, 0xD0, 0x00, 0x00,
0x01, 0x8F, 0x00, 0x00, 0x03, 0x09, 0x80, 0x00,
0x06, 0x08, 0xC0, 0x00, 0x08, 0x04, 0x40, 0x00,
0x04, 0xC2, 0x40, 0x00, 0x02, 0xE1, 0xC0, 0x00,
0x01, 0x70, 0x20, 0x00, 0x00, 0xB8, 0x10, 0x00,
0x00, 0x5C, 0x08, 0x00, 0x00, 0x2E, 0x04, 0x00,
0x00, 0x17, 0x02, 0x00, 0x00, 0x0B, 0x8B, 0x00,
0x00, 0x0D, 0xD9, 0x80, 0x00, 0x1F, 0xFC, 0xC0,
0x00, 0x3F, 0xFF, 0xE0, 0x00, 0x7F, 0xFF, 0xF8,
0x00, 0x00, 0x00, 0x00};
PROGMEM const unsigned char playerdown[] = {
// Sprite: Image + Mask
// Width: 11 Height: 24
11, 24,
//frame 0
0x00, 0xE0, 0x90, 0xDC, 0x1E, 0xFE, 0x1E, 0xDC, 0x90, 0xE0, 0x00,
0x00, 0x01, 0x02, 0xFF, 0xC2, 0xFF, 0xC2, 0xFF, 0x02, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//frame 1
0x00, 0xE0, 0x10, 0xDC, 0x1E, 0xFE, 0x1E, 0xDC, 0x90, 0xE0, 0x00,
0x00, 0x03, 0x05, 0xFF, 0xC2, 0xFF, 0xB2, 0xBF, 0x02, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//frame 2
0x00, 0xE0, 0x90, 0xDC, 0x1E, 0xFE, 0x1E, 0xDC, 0x90, 0xE0, 0x00,
0x00, 0x01, 0x02, 0xFF, 0xC2, 0xFF, 0xC2, 0xFF, 0x02, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//frame 3
0x00, 0xE0, 0x90, 0xDC, 0x1E, 0xFE, 0x1E, 0xDC, 0x10, 0xE0, 0x00,
0x00, 0x01, 0x02, 0xBF, 0xB2, 0xFF, 0xC2, 0xFF, 0x0A, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
PROGMEM const unsigned char playerdown_mask [] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
};
void setup() {
arduboy.begin();
arduboy.initRandomSeed();
crashedshipx = random(10,80);
crashedshipy = random(10, 30);
arduboy.setFrameRate(60);
arduboy.clear();
playerx = crashedshipx + 30;
playery = crashedshipy + 5;
// initialize things here
}
void loop() {
if(!arduboy.nextFrame()) {
return;
}
arduboy.clear();
if(arduboy.pressed(LEFT_BUTTON)) {
playerx = playerx - 1;
}
if(arduboy.pressed(RIGHT_BUTTON)) {
playerx = playerx + 1;
}
if(arduboy.pressed(UP_BUTTON)) {
playery = playery - 1;
}
if(arduboy.pressed(DOWN_BUTTON)) {
playery = playery + 1;
player.drawExternalMask(playerx, playery, playerdown, playerdown_mask, 1, 0); }
//For each column on the screen
for( int backgroundx = 0; backgroundx < 128; backgroundx = backgroundx + 10 ) {
//For each row in the column
for( int backgroundy = 0; backgroundy < 64; backgroundy = backgroundy + 10 ) {
//Draw a background tile
arduboy.drawSlowXYBitmap( backgroundx, backgroundy, background, 10, 10, WHITE );
}
}
player.drawExternalMask(playerx, playery, playerdown, playerdown_mask, 0, 0);
arduboy.drawSlowXYBitmap(crashedshipx,crashedshipy,crashedship,30,20,WHITE);
arduboy.display();
}