#69904 - Payk - Thu Feb 02, 2006 10:23 pm
hi i just modified the sprite_bitmap example found in devkit dirrectory.
i added more sprites and wanted to give them different gfxs. but they all ahve the same gfx.hmhmh here is my code:
Code: |
SpriteEntry sprites[128];
//Inits all we need
void OS_Init(){
//turn everything on
powerON(POWER_ALL_2D);
//irqs are nice
irqInit();
irqSet(IRQ_VBLANK, 0);
//enable vram and map it to the right places
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_0x6000000, //map C to background memory
VRAM_D_LCD //not using D
);
//set the video mode
videoSetMode( MODE_0_2D |
DISPLAY_SPR_ACTIVE | //turn on sprites
DISPLAY_SPR_2D | //this is used when in tile mode
DISPLAY_SPR_1D_BMP //and this in bitmap mode
);
// black backdrop
BG_PALETTE[0]=RGB15(0,0,25);
//init all sprites (0-11)
for(int i = 0; i < 12; i++)
{
sprites[i].attribute[0] = ATTR0_BMP | 10;
sprites[i].attribute[1] = ATTR1_SIZE_64 | 20;
sprites[i].attribute[2] = ATTR2_ALPHA(1)| i;
// sprites[i].attribute[3] = 0;
}
}
//copy our sprite to object attribute memory
void updateOAM(void)
{
DC_FlushAll();
dmaCopy(sprites, OAM, 128 * sizeof(SpriteEntry));
}
void Draw(void){
int i;
//all sprites share same buffer SHIT. how we draw them all different...
//we have to find out
for(i=0;i<64*64;i++)
SPRITE_GFX[i]=RGB15(31,0,0)|(1<<15); //just sprite0 should be red
for(i=64*64;i<64*64*2;i++)
SPRITE_GFX[i]=RGB15(0,31,0)|(1<<15); //sprite1 should be green,but all are red
}
void OS_MoveWin(u8 Win,int x,int y){
u8 xx=0,yy=0;
for(u8 i = 0; i < 12; i++)
{
if(i==0){xx=0;yy=0;}
if(i==1){xx=64;yy=0;}
if(i==2){xx=128;yy=0;}
if(i==3){xx=192;yy=0;}
if(i==4){xx=0;yy=64;}
if(i==5){xx=64;yy=64;}
if(i==6){xx=128;yy=64;}
if(i==7){xx=192;yy=64;}
if(i==8){xx=0;yy=128;}
if(i==9){xx=64;yy=128;}
if(i==10){xx=128;yy=128;}
if(i==11){xx=192;yy=128;}//Haha i know later....first it works
//ok if sprite leaves screen on right side it will appear on left again
//damn what to do? that following...
if(xx+x>255)xx=256-x;
if(yy+y>191)yy=192-y;//same is with vertical overflow
//i may wondering why not in other direction too.yes it would happen if we move
//window ouside left screen but we make it in control that window cant run out screen
//but why for right?oh if window is 64,64 the other sprites would move anyway out of screen they
//just transparent so...
sprites[i].attribute[0] = ATTR0_BMP | y+yy;
sprites[i].attribute[1] = ATTR1_SIZE_64 | x+xx;
sprites[i].attribute[2] = ATTR2_ALPHA(1)| 0;
sprites[i].attribute[3] = 0;
}
}
|
so can somebody tell me how to modify this that the sprites come with different gfxs?
#69909 - knight0fdragon - Thu Feb 02, 2006 10:57 pm
ur not changeing the location of the sprite correctly, try incrementing by 8... or 4... something like that
_________________
http://www.myspace.com/knight0fdragonds
MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206
#69911 - LiraNuna - Thu Feb 02, 2006 11:27 pm
just a little comment here,
after calling
irqInit();
irqSet(IRQ_VBLANK, 0);
also call irqEnable(IRQ_VBLANK);
if you'r going to use swiWaitForVBlank() and not calling the above function, your program will hang on the first swi call.
#69915 - Payk - Thu Feb 02, 2006 11:56 pm
hey knight0fdragon i didnt understand i am totally newbee to ndslib (i used pa_lib before). i gave a middle big code and u say that i not change the location directly. so what line was that or a quote..
did u mean that i move them wrong or that they are to close togehter. it should become a window.
#69920 - knight0fdragon - Fri Feb 03, 2006 12:10 am
Now that I look at it, how exacty are u drawing the different sprites. What i would do is load all the sprite animations into the memory,
then use the blue area to point to the start of the animation
and use the red area to change to the next frame in the animation
SpriteEntry sprites[128];
//Inits all we need
void OS_Init(){
//turn everything on
powerON(POWER_ALL_2D);
//irqs are nice
irqInit();
irqSet(IRQ_VBLANK, 0);
//enable vram and map it to the right places
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_0x6000000, //map C to background memory
VRAM_D_LCD //not using D
);
//set the video mode
videoSetMode( MODE_0_2D |
DISPLAY_SPR_ACTIVE | //turn on sprites
DISPLAY_SPR_2D | //this is used when in tile mode
DISPLAY_SPR_1D_BMP //and this in bitmap mode
);
// black backdrop
BG_PALETTE[0]=RGB15(0,0,25);
//init all sprites (0-11)
for(int i = 0; i < 12; i++)
{
sprites[i].attribute[0] = ATTR0_BMP | 10;
sprites[i].attribute[1] = ATTR1_SIZE_64 | 20;
sprites[i].attribute[2] = ATTR2_ALPHA(1)| i;
// sprites[i].attribute[3] = 0;
}
}
//copy our sprite to object attribute memory
void updateOAM(void)
{
DC_FlushAll();
dmaCopy(sprites, OAM, 128 * sizeof(SpriteEntry));
}
void Draw(void){
int i;
//all sprites share same buffer SHIT. how we draw them all different...
//we have to find out
for(i=0;i<64*64;i++)
SPRITE_GFX[i]=RGB15(31,0,0)|(1<<15); //just sprite0 should be red
for(i=64*64;i<64*64*2;i++)
SPRITE_GFX[i]=RGB15(0,31,0)|(1<<15); //sprite1 should be green,but all are red
}
void OS_MoveWin(u8 Win,int x,int y){
u8 xx=0,yy=0;
for(u8 i = 0; i < 12; i++)
{
if(i==0){xx=0;yy=0;}
if(i==1){xx=64;yy=0;}
if(i==2){xx=128;yy=0;}
if(i==3){xx=192;yy=0;}
if(i==4){xx=0;yy=64;}
if(i==5){xx=64;yy=64;}
if(i==6){xx=128;yy=64;}
if(i==7){xx=192;yy=64;}
if(i==8){xx=0;yy=128;}
if(i==9){xx=64;yy=128;}
if(i==10){xx=128;yy=128;}
if(i==11){xx=192;yy=128;}//Haha i know later....first it works
//ok if sprite leaves screen on right side it will appear on left again
//damn what to do? that following...
if(xx+x>255)xx=256-x;
if(yy+y>191)yy=192-y;//same is with vertical overflow
//i may wondering why not in other direction too.yes it would happen if we move
//window ouside left screen but we make it in control that window cant run out screen
//but why for right?oh if window is 64,64 the other sprites would move anyway out of screen they
//just transparent so...
sprites[i].attribute[0] = ATTR0_BMP | y+yy;
sprites[i].attribute[1] = ATTR1_SIZE_64 | x+xx;
sprites[i].attribute[2] = ATTR2_ALPHA(1)| 0;
sprites[i].attribute[3] = 0;
}
}
_________________
http://www.myspace.com/knight0fdragonds
MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206
#69959 - Payk - Fri Feb 03, 2006 9:51 am
ahha thanks.now they are not sharing one gfx anymore.but i am not shure how to draw them correctly
Code: |
for(i=0;i<64*64;i++)
SPRITE_GFX[i]=RGB15(31,0,0)|(1<<15); //just sprite0 should be red
for(i=64*64;i<64*64*2;i++)
SPRITE_GFX[i]=RGB15(0,31,0)|(1<<15); //sprite1 should be green,but all are red
|
so i thought SPRITE_GFX[0 to 64*64] is for sprite0 and SPRITE_GFX[64*64 to 64*64*2] is for next sprite (they have all size_64)
but is not like that. how is it? and which color is transparent...
THANX
#69964 - knight0fdragon - Fri Feb 03, 2006 11:12 am
SPRITE_GFX is 16 bits i believe, so you need to / 2
_________________
http://www.myspace.com/knight0fdragonds
MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206
#69970 - Mollusk - Fri Feb 03, 2006 12:38 pm
yes, it's 16 bit, this means you should divide by 2... Plus, you have to take this into account to draw, as you can't plot 1 pixel, but have to get the other one before plotting and plot both at a time... Adn don't forget that sprites are composed of 8x8 tiles, so you can't draw directly to postion (x, y), you first have to get the correct tile... :)
_________________
PAlib official forum : http://www.palib.info
PAlib official tutorials: http://www.palib.info/wiki
Updates, help, code examples, tutorials, etc...
#69979 - Payk - Fri Feb 03, 2006 2:15 pm
we get it all managed but still dont know which color is transparent or how to make transparents
#69987 - genfish - Fri Feb 03, 2006 4:35 pm
iv never done this before, but i think i read somewhere u set a transparent colour, then anything in the image that colour wont be drawn... is that right?
#70048 - Mollusk - Fri Feb 03, 2006 11:02 pm
transparent = not visible = color 0
_________________
PAlib official forum : http://www.palib.info
PAlib official tutorials: http://www.palib.info/wiki
Updates, help, code examples, tutorials, etc...
#70310 - genfish - Sun Feb 05, 2006 1:02 pm
rgb 0,0,0 is black :/
or is colour 0 a pre-defined thing?
#70313 - Mollusk - Sun Feb 05, 2006 2:12 pm
whatever the color, if it's at position 0 in the palette index, it won't be visible...
_________________
PAlib official forum : http://www.palib.info
PAlib official tutorials: http://www.palib.info/wiki
Updates, help, code examples, tutorials, etc...
#70371 - Payk - Sun Feb 05, 2006 11:32 pm
but i use 16bit (15bit) so there is no way to do that? or i there a way to define a transcolor?
#70393 - knight0fdragon - Mon Feb 06, 2006 3:12 am
in 16bit mode, isnt the last bit the 1 that determines the transparency
5bits Green
5bits Blue
5bits Red
1bit Alpha
_________________
http://www.myspace.com/knight0fdragonds
MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206
#70415 - Mollusk - Mon Feb 06, 2006 8:11 am
yes, I think if you leave the last bit blank it's transparent (or vice versa)
_________________
PAlib official forum : http://www.palib.info
PAlib official tutorials: http://www.palib.info/wiki
Updates, help, code examples, tutorials, etc...
#70473 - Payk - Mon Feb 06, 2006 8:06 pm
doesnt matter thanx anyway. (alphabit i remember should be like that)
#70756 - genfish - Wed Feb 08, 2006 4:11 pm
how do you load an image onto a sprite, for example, i have a bitmap of a stickman, and want to use that as a character on screen?
#71031 - tepples - Fri Feb 10, 2006 1:21 am
- In your paint program, convert the image into indexed mode. Make sure that color 0 of the palette is the one you want to be transparent (invisible, or displayed around edges).
- Convert the image into tiles (using, say, bmp2tiles).
- Include the tiles in the program (using either bin2s or GBFS, both of which come with devkitPro).
- In the program, copy the tiles into VRAM, and have one or more OAM entries refer to the tiles.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#71137 - genfish - Fri Feb 10, 2006 4:13 pm
thanks mate ill give it a shot!
#71976 - genfish - Wed Feb 15, 2006 7:59 pm
Quote: |
In your paint program, convert the image into indexed mode. Make sure that color 0 of the palette is the one you want to be transparent (invisible, or displayed around edges). |
using paint shop pro 10, when i create a new image, there is an option called colour depth. the options are things like RGB 8bit, RGB16bit. There is an index option but the maximum is only 256 colours. is this what i need to use?
edit: also which handles do i add to the cmd line of bmp2tiles?
e.g. bmp2tiles -b 8bpp timmy.bmp timmy.chr
thanks for your help :)
_________________
there is no rl only afk
#71993 - tepples - Wed Feb 15, 2006 9:34 pm
genfish wrote: |
when i create a new image, there is an option called colour depth. the options are things like RGB 8bit, RGB16bit. There is an index option but the maximum is only 256 colours. is this what i need to use? |
Yes. Most often, you'll use either 16 colors or 256 colors on the GBA. It's not a big limitation, especially given that you can use several different 16-color palettes on one screen; most Super NES games manage to look good using a 16-color graphics model similar to that of the GBA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#73619 - aik6980 - Sun Feb 26, 2006 11:28 pm
I use PSP (Paint shop pro)
it can edit palette and set transparency , very easy.
:)
I'm very noob in GBA, so I have question:
Code: |
for(loop = 0;loop<(32);loop++){
OAMData[loop] = obj0[loop];
} |
why we need to loop 32 loop for showing 8x8 sprite(32bytes), because I think it transfer by 16bit/loop, it mean 16 times loop is enough.
What's wrong?
[/code]
#73720 - Payk - Mon Feb 27, 2006 8:40 pm
haha that was good idea to write that u use Paint Shop Pro (because PSP could be missunderstood...) hehe... i hear them scream "ur at gbadev...".ok perhaps nobody would scream...
#73846 - aik6980 - Tue Feb 28, 2006 9:29 am
T-T
I don't mean that, but somebody here said PSP is the poppular tool for you dealing with graphic.
anyway, now I stuck in Timer usage in my game. I try to read TONC, however, do you have any more tutorials about this?
Thank a lot