Bug with cell based imagemaps
by Greg Lincoln · in Torque Game Builder · 03/14/2005 (4:45 pm) · 3 replies
I found a bug (I think) in the code that loads imagemaps in "cell mode." (BTW, sorry if this has already been reported. I searched and couldn't find any mention of it.)
The problem is that it seems to cut off a row of pixels from the bottom and the right sides.
Here are two pictures that illustrate the problem, and below them you can see the code I changed to fix it.
This picture shows the bad behavior. On the left, there is a 32x32 png image loaded in "full" mode. On the right we see frame 0 of a 128x32 png image loaded as cells. You can see how the image on the right is off center.

Here's the expected behavior, after my fix, using the same datamaps and sprites:

I changed the line below in the method fxImageMapDatablock2D::calculateCellImageMap: (linefeeds added for size)
//tMapRegion region = { x*mCellWidth * mTexelWidth, y*mCellHeight * mTexelHeight,
(x*mCellWidth+mCellWidth-1) * mTexelWidth, (y*mCellHeight+mCellHeight-1) * mTexelHeight };
tMapRegion region = { x*mCellWidth * mTexelWidth, y*mCellHeight * mTexelHeight,
(x*mCellWidth+mCellWidth) * mTexelWidth, (y*mCellHeight+mCellHeight) * mTexelHeight };
The commented line is how it was, and below shows that I removed the -1 from the second coordinate pair for my fix. I have no idea if this will break something else or if this is a "wrong" fix, but it seems to work for me. YMMV.
Greg
The problem is that it seems to cut off a row of pixels from the bottom and the right sides.
Here are two pictures that illustrate the problem, and below them you can see the code I changed to fix it.
This picture shows the bad behavior. On the left, there is a 32x32 png image loaded in "full" mode. On the right we see frame 0 of a 128x32 png image loaded as cells. You can see how the image on the right is off center.

Here's the expected behavior, after my fix, using the same datamaps and sprites:

I changed the line below in the method fxImageMapDatablock2D::calculateCellImageMap: (linefeeds added for size)
//tMapRegion region = { x*mCellWidth * mTexelWidth, y*mCellHeight * mTexelHeight,
(x*mCellWidth+mCellWidth-1) * mTexelWidth, (y*mCellHeight+mCellHeight-1) * mTexelHeight };
tMapRegion region = { x*mCellWidth * mTexelWidth, y*mCellHeight * mTexelHeight,
(x*mCellWidth+mCellWidth) * mTexelWidth, (y*mCellHeight+mCellHeight) * mTexelHeight };
The commented line is how it was, and below shows that I removed the -1 from the second coordinate pair for my fix. I have no idea if this will break something else or if this is a "wrong" fix, but it seems to work for me. YMMV.
Greg
About the author
Associate Melv May
Thanks again.
- Melv.