gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > problem with sprites

#33274 - ferr - Sat Jan 01, 2005 11:50 am

i'm reading through the pern project thing which i found in the gbadev.org faq sticky thread, and i'm having a problem with sprites.

here's the tutorial i'm using (it's demo 1) :
http://www.thepernproject.com/English/day_3.html

1) the sprite becomes truncated: the image is supposed (i would think) to be 64x64 on a 64x64 "palette" but it seems as if it is truncating the image to 64x32 then placing it on a 64x32 palette. it seems that SQUARE, SIZE_64 is actually 64x32 when it should be 64x64 (according to the tut). i've messed with other formats like SQUARE, SIZE_32 and it does the same exact (proportional) truncation.

2) i can't figure out the damn transparent color attribute, he says: "Color zero, no matter its RGB value, will not be rendered onto the GBA screen so use this to color the portions of your image that you do not want blitted" and his sprite 'background' is R204, G153, B255.. and this is not transparent in emulation, hardware, or the images on his site. i looked into the video.h include and found " #define MODE_TRANSPERANT BIT(0xA) " What is BIT(0xA)? I looked into another GBA source and found someone using BIT10, which is apparently black. is there a list somewhere that explains what each bit is for this? right now i can't even test if BIT10 works correctly since the background in the sprite demo is also black and i haven't the slightest idea how to change that, but i'll just have to assume it does since it works in the other program.

the thing is, he has images in his tutorial that display the same things which just shouldn't be such as truncated sprites and non-transparent sprite BGs, but never mentions them.

***
edit: found the problem with the truncation, i don't remember changing it but the mapping mode was set to 2D instead of 1D. still trying to figure out the transparency.
edit: just noticed he covers alpha blending in Day 9 according to the day 3 tutorial. too bad he stopped at Day 6.

anyone know of a tutorial similar to the pern project.. except complete?

#33284 - pyros - Sat Jan 01, 2005 4:48 pm

I assume you are using a paint package to draw your sprites and convert them to 256 colours, and then using another program to convert them to a .h file. Well, use colour 'zero' the first colour of the pallette for transparency. This is usually at the top-left of a grid of colours displaying your pallette. Inside the 'sprites.h', pixels represented with a byte of value zero will be drawn as transparent.

I'd follow pern, then woek through tonc. That covers transparency and more.

http://user.chem.tue.nl/jakvijn/tonc/toc.htm

#33294 - ferr - Sat Jan 01, 2005 6:32 pm

pyros wrote:
I assume you are using a paint package to draw your sprites and convert them to 256 colours, and then using another program to convert them to a .h file. Well, use colour 'zero' the first colour of the pallette for transparency. This is usually at the top-left of a grid of colours displaying your pallette. Inside the 'sprites.h', pixels represented with a byte of value zero will be drawn as transparent.

I'd follow pern, then woek through tonc. That covers transparency and more.

http://user.chem.tue.nl/jakvijn/tonc/toc.htm


using Paint Shop Pro to get the sprite to 256 colors and into .PCX format, then using a .gba batch compiler which triggers PCX2SPRITE which, in addition to the final .GBA, produces the sprite header file, but this is all that's within that sprite header file:
Code:
extern unsigned short spriteData[];
extern unsigned short spritePalette[];

have to assume the sprite data is mapped directly to .GBA in this process.

***
edit: thanks for the link.

#33338 - AnthC - Sun Jan 02, 2005 2:36 am

ferr wrote:
i'm reading through the pern project thing which i found in the gbadev.org faq sticky thread, and i'm having a problem with sprites.

here's the tutorial i'm using (it's demo 1) :
http://www.thepernproject.com/English/day_3.html

1) the sprite becomes truncated: the image is supposed (i would think) to be 64x64 on a 64x64 "palette" but it seems as if it is truncating the image to 64x32 then placing it on a 64x32 palette. it seems that SQUARE, SIZE_64 is actually 64x32 when it should be 64x64 (according to the tut). i've messed with other formats like SQUARE, SIZE_32 and it does the same exact (proportional) truncation.



I've looked at the code briefly and it seems that it is putting 00 in bits 15,14 in attribute 0. This means the sprite should be square.
Also bits 15,14 are set to 11 in attribute 1 thus making the sprite 64x64 pixels. I've also looked at the code in the emulator and it seems to be fine.

ferr wrote:


2) i can't figure out the damn transparent color attribute, he says: "Color zero, no matter its RGB value, will not be rendered onto the GBA screen so use this to color the portions of your image that you do not want blitted" and his sprite 'background' is R204, G153, B255.. and this is not transparent in emulation, hardware, or the images on his site. i looked into the video.h include and found " #define MODE_TRANSPERANT BIT(0xA) " What is BIT(0xA)? I looked into another GBA source and found someone using BIT10, which is apparently black. is there a list somewhere that explains what each bit is for this? right now i can't even test if BIT10 works correctly since the background in the sprite demo is also black and i haven't the slightest idea how to change that, but i'll just have to assume it does since it works in the other program.



With 16 & 256 colour sprites, colour index 0 in your sprite is transparent.
With 16 colour sprites the palette is selected using bits 15,14,13,12 in attribute 2, giving 16 'banks' of 16 colours.

If your sprite data consisted of all 1's and you selected palette 2 to use for the sprite, then the colour displayed on screen would be 2*16+1 = 33
So a pixel colour from the 33rd sprite palette index would be displayed.
Had your sprite consisted of all 0's then the sprite should be invisible.