#41117 - Strobe - Mon Apr 25, 2005 2:09 pm
Hi All,
I've only just started off coding for the GBA and so far i've made some great progress thanks to the wealth of onfo available on this forum. I'm going to stick my neck out though and ask for help on a problem that i haven't been able to find any previous postings for.
Please excuse me if this doesn't make any sense.
I've been playing aroud with collision detection for a sprite against a text background. I created a collision map with MapEd and have been able to get bounding box detection working with thanks to staringmonkey and his RPG demo code. However I've also been wanting to do some some per pixel detection and tried playing around with the function in staringmonkeys code. This seems to work when i use a sprite that is only 1 tile wide and however many high but doesn't if the sprite is 2 or more tiles wide. I'm trying to do a 16 x 16 sprite with some transparency around the edges. After using pcx2gba to create the sprite data and setting the transparent pixels to value 0 i can display the sprite with no problems however i can't get the collision detection routine to work correctly.
I'm using 1D mapping for the sprites and the problems seems to be with indexing the current pixel being processed for collision against the sprite data to see if it is transparent(solid or not). I'm checking the sprite data just as below
for(y = 0; y < height; y++) //Height is 16
{
for(x = 0; x < width; x++) //Width is 16
{
if(sprite[y*width+x])
I can see from looking at the sprite data produced by pcx2gba that it is arranged tile by tile and not in a linear fashion like a bitmap. If that makes sense.
In other words if the value checked evaluates to
if(sprite[10])
then this will check the 10th pixel of the 1st tile rather than the 2nd pixel of the secod tile along the top.
I'm guessing i need to calculate some kind of offset based on the number and format of the tiles in the sprite?
This probably makes no sense as i've gone round in circles and got my head too far into the problem to step back. Either that or there is a much better way of doing pixel level collision?
However, if anyone can understand the issue i'm having and can offer a solution i would be most grateful.
Thanks again
I've only just started off coding for the GBA and so far i've made some great progress thanks to the wealth of onfo available on this forum. I'm going to stick my neck out though and ask for help on a problem that i haven't been able to find any previous postings for.
Please excuse me if this doesn't make any sense.
I've been playing aroud with collision detection for a sprite against a text background. I created a collision map with MapEd and have been able to get bounding box detection working with thanks to staringmonkey and his RPG demo code. However I've also been wanting to do some some per pixel detection and tried playing around with the function in staringmonkeys code. This seems to work when i use a sprite that is only 1 tile wide and however many high but doesn't if the sprite is 2 or more tiles wide. I'm trying to do a 16 x 16 sprite with some transparency around the edges. After using pcx2gba to create the sprite data and setting the transparent pixels to value 0 i can display the sprite with no problems however i can't get the collision detection routine to work correctly.
I'm using 1D mapping for the sprites and the problems seems to be with indexing the current pixel being processed for collision against the sprite data to see if it is transparent(solid or not). I'm checking the sprite data just as below
for(y = 0; y < height; y++) //Height is 16
{
for(x = 0; x < width; x++) //Width is 16
{
if(sprite[y*width+x])
I can see from looking at the sprite data produced by pcx2gba that it is arranged tile by tile and not in a linear fashion like a bitmap. If that makes sense.
In other words if the value checked evaluates to
if(sprite[10])
then this will check the 10th pixel of the 1st tile rather than the 2nd pixel of the secod tile along the top.
I'm guessing i need to calculate some kind of offset based on the number and format of the tiles in the sprite?
This probably makes no sense as i've gone round in circles and got my head too far into the problem to step back. Either that or there is a much better way of doing pixel level collision?
However, if anyone can understand the issue i'm having and can offer a solution i would be most grateful.
Thanks again