Reputation: 3428
I'm trying to write a very basic GBA game.
I have been reading the tonc examples and am using the tonc lib. I have something that builds and runs, but I am failing to get a sprite to draw over a background. At the moment, the background renders ok, but the object over the top just appears as a glitchy pink square in the top left of the screen.
int main ()
{
initMain();
while(1)
{
vid_vsync();
key_poll();
updateMain();
}
return 0;
}
void initMain()
{
// background
memcpy(pal_bg_mem, backgroundPal, backgroundPalLen);
memcpy(&tile_mem[0][0], backgroundTiles, backgroundTilesLen);
memcpy(&se_mem[30][0], backgroundMap, backgroundMapLen);
// character
memcpy(pal_obj_mem, characterPal, characterPalLen);
memcpy(&tile_mem[4][0], characterTiles, characterTilesLen);
oam_init(obj_buffer, 128);
REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_8BPP | BG_REG_32x32;
REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_OBJ | DCNT_OBJ_1D;
}
void updateMain()
{
// character
int x = 96, y = 96;
u32 tid = 0, pb = 0;
OBJ_ATTR *character = &obj_buffer[0];
obj_set_attr(character,
ATTR0_SQUARE, // Square, regular sprite
ATTR1_SIZE_64, // 64x64p,
ATTR2_PALBANK(pb) | tid); // palbank 0, tile 0
character->attr2 = ATTR2_BUILD(tid, pb, 2);
obj_set_pos(character, x, y);
oam_copy(oam_mem, obj_buffer, 1);
REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_OBJ | DCNT_OBJ_1D ;
}
I am no doubt making a basic mistake and just need a little bit of help to understand what I've done wrong here.
Upvotes: 1
Views: 291