Page 1 of 1

sprites help.

Posted: Fri Mar 27, 2009 4:20 pm
by opearn
hi everyone
i'm trying to load a sprite using this code

Code: Select all

#include <nds.h>
#include "drunkenlogo.h"

int main(void) {
	videoSetMode(MODE_0_2D);
	vramSetBankA(VRAM_A_MAIN_SPRITE);
	u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_256Color);
	dmaCopy(drunkenlogoBitmap, gfx, 32*32);
	dmaCopy(drunkenlogoPal, SPRITE_PALETTE, 512);
	while(1) {
		oamSet(&oamMain,0,32,32,0,0,SpriteSize_64x64,SpriteColorFormat_256Color,gfx,-1,false,false,false,false,false);
		swiWaitForVBlank();
		oamUpdate(&oamMain);
	}
	return 0;
}
what do i need to change to make it work?
note: i'm new to libnds's sprites

Re: sprites help.

Posted: Fri Mar 27, 2009 6:08 pm
by Sylus101
Off the top of my head, you're missing a call to oamInit() before you allocate memory for the gfx. Are you working from the examples?

Re: sprites help.

Posted: Sat Mar 28, 2009 1:10 am
by opearn
yeah soz about that, this is a extract from my app and i accidently left that out
but thanks for your help

EDIT* after examining pataters tutorial i have made my simple sprite code.

Here it is

Code: Select all

 /*-------------------------------------------------------------\
|	opearns sprite code										|
| 		based off the devkitpro examples and pataters tut.		|
 \-------------------------------------------------------------*/
#include <nds.h>
#include "drunkenlogo.h"

int main(void) {
	videoSetMode(MODE_0_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D);//set the video mode to 2d
	vramSetBankA(VRAM_A_MAIN_SPRITE); //set up some VRam for sprites
	oamInit(&oamMain, SpriteMapping_Bmp_1D_128, false); //initialize the oam
	u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_256Color);//setup the sprite
	dmaCopy(drunkenlogoTiles, gfx, drunkenlogoTilesLen);//load the sprite to gfx (last line)
	dmaCopy(drunkenlogoPal, SPRITE_PALETTE, drunkenlogoPalLen); //copy the sprites palette
	while(1) {//infinite loop
		oamSet(&oamMain,0,32,32,0,0,SpriteSize_64x64,SpriteColorFormat_256Color,gfx,-1,false,false,false,false,false);
		swiWaitForVBlank();
		oamUpdate(&oamMain);
	}
	return 0;
}
the grit has to use tiles so the code for that is here

Code: Select all

# 8 bit bitmap

-gB8

# Tile the image
-gt