Homebrew [Help] NDS dev – Sprite not showing on screen (libnds / grit)

  • Thread starter Thread starter Majencio33
  • Start date Start date
  • Views Views 258
  • Replies Replies 1

Majencio33

New Member
Newbie
Joined
Aug 23, 2025
Messages
1
Reaction score
0
Trophies
0
Age
34
XP
19
Country
Spain
Hi everyone,


I’m starting with homebrew development on the Nintendo DS and I’m trying to display a simple 8x8 sprite on the SUB (bottom) screen.

My PNG is 16x16 pixels and contains 4 sub-sprites of 8x8. I exported it using grit with this command:


grit flechas.png -gt -gB2 -tw 8 -th 8 -p -m!
Here’s the full C code I’m using with libnds, but the sprite does not appear on the screen:

#include <nds.h>
#include <stdio.h>
#include "sprites/flechas.h"

void Vblank() {}

int main(void) {
irqSet(IRQ_VBLANK, Vblank);

videoSetModeSub(MODE_0_2D);
vramSetBankI(VRAM_I_SUB_SPRITE);

oamInit(&oamSub, SpriteMapping_1D_32, false);

// Copy palette to SUB sprite memory
dmaCopy(flechasPal, SPRITE_PALETTE_SUB, flechasPalLen);

// Allocate VRAM for a 16x16 sprite
u16* gfx = oamAllocateGfx(&oamSub, SpriteSize_16x16, SpriteColorFormat_16Color);
dmaCopy(flechasTiles, gfx, flechasTilesLen);

// Set up the sprite
oamSet(&oamSub, 0, 80, 50, 0, 0,
SpriteSize_16x16, SpriteColorFormat_16Color,
gfx, -1, false, false, false, false, false);

while(1) {
swiWaitForVBlank();
oamUpdate(&oamSub);
}

return 0;
}

This is the header file generated by grit for my sprite flechas.png:



//{{BLOCK(flechas)

//======================================================================
//
// flechas, 16x16@2,
// + palette 256 entries, not compressed
// + 4 tiles not compressed
// Total size: 512 + 64 = 576
//
// Time-stamp: 2025-08-23, 19:52:36
// Exported by Cearn's GBA Image Transmogrifier, v0.9.2
//
//
//======================================================================

#ifndef GRIT_FLECHAS_H
#define GRIT_FLECHAS_H

#define flechasTilesLen 64
extern const unsigned int flechasTiles[16];

#define flechasPalLen 512
extern const unsigned short flechasPal[256];

#endif // GRIT_FLECHAS_H

//}}BLOCK(flechas)


 
Hi there, your header tells that your image is in fact 8-bit depth (256 colors).
If grit recognize it as 4-bit (16 colors) image felchasPalLen should be 32 bytes long.
First try to convert your image in gimp or other graphical program to lesser size.
Also 16-colors image should be 4-bit depth for grit -gB parameter (-gB4 instead of -gB2).
I compiled your code with my png image and it shows some sprite.
 
Last edited by plasturion,

Site & Scene News

Popular threads in this forum