Simple OAM (Sprite) Beginner Problem (Solved)

Post Reply
asmodeus
Posts: 2
Joined: Tue Dec 22, 2009 6:34 pm

Simple OAM (Sprite) Beginner Problem (Solved)

Post by asmodeus » Tue Dec 22, 2009 6:53 pm

Hello, I'm very new at DS development. I could already draw 16 bit pixels to both DS screens, and now I'd like to try sprites.
This is my code so far:

Code: Select all

#include <nds.h>

// my function defined elsewhere, not important here
extern void loadTitleGfx(u16 *buffer_main, u16 *buffer_sub);

int main()
{
        // pointer to the bg rams, where I can paint the bg layers
	u16 *video_buffer = (u16*)BG_BMP_RAM(0);
	u16 *video_buffer_sub = (u16*)BG_BMP_RAM_SUB(0);
	
        // I set mode 5 for both screens, and I enable bg3 for both
	videoSetMode(MODE_5_2D|DISPLAY_BG3_ACTIVE);
	videoSetModeSub(MODE_5_2D|DISPLAY_BG3_ACTIVE);
	
        // I don't really have much clue about this... when can I use which bank?
	vramSetBankA(VRAM_A_MAIN_BG);
	vramSetBankC(VRAM_C_SUB_BG);
	vramSetBankD(VRAM_D_SUB_SPRITE);
	
        // setting the backgrounds
	BACKGROUND.control[3] = BG_BMP16_256x256|BG_BMP_BASE(0);
	BACKGROUND.bg3_rotation.xdy = 0;
	BACKGROUND.bg3_rotation.xdx = 1<<8;
	BACKGROUND.bg3_rotation.ydx = 0;
	BACKGROUND.bg3_rotation.ydy = 1<<8;
	
	BACKGROUND_SUB.control[3] = BG_BMP16_256x256|BG_BMP_BASE(0)|BG_PRIORITY(1);
	BACKGROUND_SUB.bg3_rotation.xdy = 0;
	BACKGROUND_SUB.bg3_rotation.xdx = 1<<8;
	BACKGROUND_SUB.bg3_rotation.ydx = 0;
	BACKGROUND_SUB.bg3_rotation.ydy = 1<<8;
	
        // load title screens from memory and draw to bg3 layer main and sub, my custom function
	loadTitleGfx(video_buffer, video_buffer_sub);
	

        /////////////////////////////////////////////////////////
        // THIS IS THE PART WHERE I HAVE PROBLEMS!
        /////////////////////////////////////////////////////////

        // init oam on sub screen
	oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false);

        // sprite now points to the memory, where I can draw with ARGB16() like in VRAM?
	u16 *sprite = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_Bmp);
        // just fill the whole sprite with red color, alpha=1 (visible), correct?
	for(int i=0;i<256;i++) sprite[i] = ARGB16(1, 31, 0, 0);


        // main game loop
	while(1)
	{
	  oamSet(&oamSub, 0, 128, 64, 0, 0, SpriteSize_16x16, SpriteColorFormat_Bmp, sprite, 0,
	         false, false, false, false, false);
	  swiWaitForVBlank();
	  oamUpdate(&oamSub);
	}
	
	return 0;
}
I have never gotten to draw any sprites on screen. Where am I doing something wrong? I've also debugged with an emulator, where I can't see my red square sprite in the data using utilities.
Can anybody please help me?
Last edited by asmodeus on Tue Dec 22, 2009 9:41 pm, edited 1 time in total.

RyouArashi
Posts: 29
Joined: Sun Mar 29, 2009 9:23 pm

Re: Simple OAM (Sprite) Beginner Problem

Post by RyouArashi » Tue Dec 22, 2009 8:37 pm

This may be the error:

Code: Select all

u16 *sprite = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_Bmp);
Change oamMain to oamSub

asmodeus
Posts: 2
Joined: Tue Dec 22, 2009 6:34 pm

Re: Simple OAM (Sprite) Beginner Problem

Post by asmodeus » Tue Dec 22, 2009 9:41 pm

oh, such a stupid mistake ^^
now it works as it should. Thank you very much.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests