#7436 - mandarin - Tue Jun 17, 2003 10:12 pm
Ok here are my questions ....how do u set priority in sprites (give me sample code) .....howcome when i use the following function i wrote writes both sprites to the screen but the one flashes away in a millisecond? Help me out here....please
Code: |
int displayitems(u16 x, u16 y, u16 no)
{
u16 loop;
u16 num;
u16 attrnum;
attrnum=0;
attrnum=no*8;
num=0;
num=no;
for(loop=0; loop < 128 ; loop++) {
OBJPaletteMem[loop] = itemsPalette[loop];
}
initsprites(); //sets sprites of screen in case you're wondering
sprites[no].attribute0 = COLOR_256 | SQUARE | y;
sprites[no].attribute1 = SIZE_16 | x;
sprites[no].attribute2 = attrnum | PRIORITY(1);
if (no = 0) {
num=num+128;
for(loop = 0; loop < 128;loop++)
{
OAMData[loop] = itemsData[loop];
}
}
else {
num=(num+1)*128;
for(loop = 128; loop <num;loop++)
{
OAMData[loop] = itemsData[loop-128];
}
}
}
int main()
{
setmode( mode2 | objenable | objmap1d );
displayitems(100,100,1);
displayitems(120,120,2);
while (1) {
WaitForVsync();
CopyOAM();
}
} |
#7480 - Sweex - Wed Jun 18, 2003 4:04 pm
I believe the sprites are drawn in their order. So sprite 0 is drawn on top of everything, sprite 1 is below 0 but on top of 2-127. (Might just be the other way around).
Also, there is a hardware limit to the amount of sprites / scanline. Don't know the exact numbers for this but I believe there is a (brief) description of this in the Cowbite hardware spec. document. If you exceed this limit, sprites will flicker or appear only partially...
#7482 - niltsair - Wed Jun 18, 2003 4:21 pm
"I believe the sprites are drawn in their order. So sprite 0 is drawn on top of everything, sprite 1 is below 0 but on top of 2-127."
Only true if both Sprite have the asme priority. Priority is determine like this :
Code: |
if Priority Sprite A < Sprite B
Sprite A on top
else if Priority Sprite B < Sprite A
Sprite B on top
//Sprite have same priority
else
if number SpriteA < Sprite B
SpriteA on top
else
SpriteB on top
|
#7498 - tepples - Wed Jun 18, 2003 6:38 pm
niltsair wrote: |
"I believe the sprites are drawn in their order. So sprite 0 is drawn on top of everything, sprite 1 is below 0 but on top of 2-127."
Only true if both Sprite have the asme priority. |
The sprites are drawn in order, front to back. The sprite priority bits are used for priority against the background. If sprite 0 with background priority 1 overlaps sprite 1 with background priority 0, and there's a background layer with background priority 0 between the sprites, then the GBA will put the background pixels in front of any place where they overlap. The NES acted the same way, and priority tricks were common for knocking out a "window" in a sprite.
If you're not trying to do something dodgy like this, then make sure all prio-0 sprites appear in OAM before all prio-1 sprites, etc.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#7500 - niltsair - Wed Jun 18, 2003 6:56 pm
Interesting, didn't knew that.
#7503 - mandarin - Wed Jun 18, 2003 8:06 pm
Thanx but there is still a problem
giving i define priority on all my sprites as 0 and i set my funtion to the following...
displayitem(120,120,0);
it still just flashes...eg:
say i define
displayitem(120,120,0); //and then
displayitem(60,60,1);
it then flashes the displayitem(120,120,0);
and only displays displayitem(60,60,1);
please help here...if there is something wrong with my function plz point that out to plz.
#7507 - niltsair - Wed Jun 18, 2003 9:31 pm
You re-initialize all fo your sprites every time you call DisplayItem. The way it should be is :
1. Call InitSprites
2. Call DisplayItem
3. Call DisplayItem
That's it. Remove all sprite init code in DisplayItem and only keep the code that set the property of 1 OAM.
Code: |
//....
/* Remove this, make syre it's in InitSprite or somewhere else, as logn as you call it once
for(loop=0; loop < 128 ; loop++)
OBJPaletteMem[loop] = itemsPalette[loop];
*/
/* Remove this, call it once in Main
initsprites(); //sets sprites of screen in case you're wondering
*/
//Good code
sprites[no].attribute0 = COLOR_256 | SQUARE | y;
sprites[no].attribute1 = SIZE_16 | x;
sprites[no].attribute2 = attrnum | PRIORITY(1);
OAMData[no] = itemsData[no];
/* What is this for ???
if (no = 0)
{
num=num+128;
for(loop = 0; loop < 128;loop++)
OAMData[loop] = itemsData[loop];
}
else
{
num=(num+1)*128;
for(loop = 128; loop <num;loop++)
OAMData[loop] = itemsData[loop-128];
}
*/
//....
|
This code won't work, you'll have to adjust some stuff. By the only thing you have to understand is to initialize sprite once, and then modify each sprite individually, not every one of them everytime.
One way woudl be to keep an array of the individual sprite's values, and once per frame, you DMA the 128 sprite's value in the array to the OAM, thus you don't have to wait for VBlank for every sprite change.
#7539 - mandarin - Thu Jun 19, 2003 5:11 pm
thanx man but heres the funny thing i just figured that out this morning on my own that the initsprites(); should only be called once bcoz if i call it twice it sets the first sprite of screen thats why it flashes away.
Thanx anyway.
But I got a different problem now when i use the function and i want to call my character sprite with displaycharacter(34,45,3);
its exactly the same function except the sprite is 32x32 but now you see the new problem is when i load the palette into memory of this sprite it has the same as the items palette even though the character's palette is different. How can i fix this....i tried
Code: |
for(loop = 128; loop < 256;loop++)
OBJPaletteMem[loop] = characterPalette[loop-128];
please help |
#7540 - niltsair - Thu Jun 19, 2003 5:18 pm
The thing is, there's either 1 palette of 256 colors that all sprites use or 16 palettes of 16 colors that sprites also al share. No getting around it. So, you either create 1 palette for the 2 sprites or use two 16 colors palette for your 2 sprites.
Another way could be to decided that sprite 1 will use color 0-127 and sprite 2 color 128-255. Then load both palette to form one 256colors palette and when loading the pixel of sprite 2, add 128 to each of them.
So basicly, there's only 1 256colors palette entry available. Hardware allow you to either use it as 1 palette, or as 16x 16colors palette.
#7543 - mandarin - Thu Jun 19, 2003 5:25 pm
so in other words i can basically have a maximum of 2 256color sprites?
I don't know i really battle to understand the palette concept plz help.
#7546 - niltsair - Thu Jun 19, 2003 5:57 pm
No, there's one 256colors sprites palette. Can be use as a whole, or as 16x 16colors palette.
#7547 - mandarin - Thu Jun 19, 2003 6:03 pm
gee wiz...thats not much
if i want to use 16x16 must i save the pcx file in 16 color mode?
#7553 - niltsair - Thu Jun 19, 2003 7:27 pm
Yes, and when converting it to binaries, following a 16colors format when using your conversino tool.
#7612 - Cyberman - Sat Jun 21, 2003 12:40 am
mandarin wrote: |
gee wiz...thats not much
if i want to use 16x16 must i save the pcx file in 16 color mode? |
Umm no he means 1 256 color palette not 1 sprite.
You have 256 colors for the sprite palette.
this gives you 16 16 color sprite palette's. You can have 16 color and 256 color sprites intermixed.
As for using 16x16 sprite you can use 256 or a 16 color palette. the sprite sizes can be 8x8 to 64x64 in size.
Just remember a 16color sprite uses 1/2 the memory a 256 color one does.
Cyb