#150050 - juniorE - Tue Jan 29, 2008 11:09 am
Hello all,
I have a problem with sprites. I would like to do for nds program 2 Sprites, with 2 different texture. For this I converted any image (resolution 32x32 px) with Palib-converter in each case into sprites file(*.c) and palette file(*.c). For copying of sprites palette and sprites object info I use dmaCopy () Function. Indeed, both spirits are displayed, but sprite 2 is not displayed right (texture is distorted ). I think, that it could be because of different SPRITE_PALETTEs, because I do't know, how can I create a common one palette for 2 images.
If anyone can give some tips that would be awesome.
Thank you!- :)
Here is my code:
// Sprite files :
#include "butt_6.c"
#include "butt_2.c"
// Palette files
#include "butt_2.pal.c"
#include "butt_6.pal.c"
SpriteEntry sprites[128];
pSpriteRotation spriteRotations = (pSpriteRotation)sprites;
//turn off all the sprites
void initSprites(void)
{
for(int i = 0; i < 128; i++)
{
sprites[i].attribute[0] = ATTR0_DISABLED;
sprites[i].attribute[1] = 0;
sprites[i].attribute[2] = 0;
sprites[i].attribute[3] = 0;
}
}
//copy our sprite to object attribute memory
void updateOAM(void)
{
DC_FlushRange(sprites,128*sizeof(SpriteEntry));
dmaCopy(sprites, OAM, 128 * sizeof(SpriteEntry));
}
int main()
{
powerON(POWER_ALL_2D);
irqInit();
irqSet(IRQ_VBLANK, 0);
vramSetMainBanks( VRAM_A_MAIN_SPRITE, //A and B maped consecutivly as sprite memory
VRAM_B_MAIN_SPRITE, //this gives us 256KB which is the max
VRAM_C_MAIN_BG_0x06000000, //map C to background memory
VRAM_D_LCD //not using D
);
vramSetBankE(VRAM_E_MAIN_SPRITE);
//set the video mode
videoSetMode( MODE_0_2D |
DISPLAY_SPR_ACTIVE | //turn on sprites
DISPLAY_BG0_ACTIVE | //turn on background 0
DISPLAY_SPR_1D | //this is used when in tile mode
DISPLAY_SPR_1D_BMP //and this in bitmap mode
);
BG_PALETTE[0]=RGB15(0,0,0);
BG0_CR = BG_MAP_BASE(31);//use bg0 for the text
BG_PALETTE[255] = RGB15(31,31,31);//by default font rendered with color 255
initSprites();
sprites[1].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 80;
sprites[1].attribute[1] = ATTR1_SIZE_32 | 10; // size 64x64, x 10
sprites[1].attribute[2] = 0| ATTR2_PALETTE(0);
dmaCopy(butt_6_Pal, &SPRITE_PALETTE[0], sizeof(butt_6_Pal));
dmaCopy(butt_6_Sprite, &SPRITE_GFX[0 * 16],sizeof( butt_6_Sprite));
sprites[2].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 80;
sprites[2].attribute[1] = ATTR1_SIZE_32 | 50;
sprites[2].attribute[2] = 64| ATTR2_PALETTE(1);;
dmaCopy(butt_2_Pal, &SPRITE_PALETTE[sizeof(butt_6_Pal)/2], sizeof(butt_2_Pal));
dmaCopy(butt_2_Sprite, &SPRITE_GFX[64 * 16],sizeof( butt_2_Sprite));
updateOAM();
while(1)
{
swiWaitForVBlank();
updateOAM();
}
}
[code][/code]
I have a problem with sprites. I would like to do for nds program 2 Sprites, with 2 different texture. For this I converted any image (resolution 32x32 px) with Palib-converter in each case into sprites file(*.c) and palette file(*.c). For copying of sprites palette and sprites object info I use dmaCopy () Function. Indeed, both spirits are displayed, but sprite 2 is not displayed right (texture is distorted ). I think, that it could be because of different SPRITE_PALETTEs, because I do't know, how can I create a common one palette for 2 images.
If anyone can give some tips that would be awesome.
Thank you!- :)
Here is my code:
// Sprite files :
#include "butt_6.c"
#include "butt_2.c"
// Palette files
#include "butt_2.pal.c"
#include "butt_6.pal.c"
SpriteEntry sprites[128];
pSpriteRotation spriteRotations = (pSpriteRotation)sprites;
//turn off all the sprites
void initSprites(void)
{
for(int i = 0; i < 128; i++)
{
sprites[i].attribute[0] = ATTR0_DISABLED;
sprites[i].attribute[1] = 0;
sprites[i].attribute[2] = 0;
sprites[i].attribute[3] = 0;
}
}
//copy our sprite to object attribute memory
void updateOAM(void)
{
DC_FlushRange(sprites,128*sizeof(SpriteEntry));
dmaCopy(sprites, OAM, 128 * sizeof(SpriteEntry));
}
int main()
{
powerON(POWER_ALL_2D);
irqInit();
irqSet(IRQ_VBLANK, 0);
vramSetMainBanks( VRAM_A_MAIN_SPRITE, //A and B maped consecutivly as sprite memory
VRAM_B_MAIN_SPRITE, //this gives us 256KB which is the max
VRAM_C_MAIN_BG_0x06000000, //map C to background memory
VRAM_D_LCD //not using D
);
vramSetBankE(VRAM_E_MAIN_SPRITE);
//set the video mode
videoSetMode( MODE_0_2D |
DISPLAY_SPR_ACTIVE | //turn on sprites
DISPLAY_BG0_ACTIVE | //turn on background 0
DISPLAY_SPR_1D | //this is used when in tile mode
DISPLAY_SPR_1D_BMP //and this in bitmap mode
);
BG_PALETTE[0]=RGB15(0,0,0);
BG0_CR = BG_MAP_BASE(31);//use bg0 for the text
BG_PALETTE[255] = RGB15(31,31,31);//by default font rendered with color 255
initSprites();
sprites[1].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 80;
sprites[1].attribute[1] = ATTR1_SIZE_32 | 10; // size 64x64, x 10
sprites[1].attribute[2] = 0| ATTR2_PALETTE(0);
dmaCopy(butt_6_Pal, &SPRITE_PALETTE[0], sizeof(butt_6_Pal));
dmaCopy(butt_6_Sprite, &SPRITE_GFX[0 * 16],sizeof( butt_6_Sprite));
sprites[2].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 80;
sprites[2].attribute[1] = ATTR1_SIZE_32 | 50;
sprites[2].attribute[2] = 64| ATTR2_PALETTE(1);;
dmaCopy(butt_2_Pal, &SPRITE_PALETTE[sizeof(butt_6_Pal)/2], sizeof(butt_2_Pal));
dmaCopy(butt_2_Sprite, &SPRITE_GFX[64 * 16],sizeof( butt_2_Sprite));
updateOAM();
while(1)
{
swiWaitForVBlank();
updateOAM();
}
}
[code][/code]