|
-
Apr 19th, 2005, 12:35 AM
#1
Thread Starter
Addicted Member
Looking up tiles
Okay im having trouble working out the math of looking up a tile from a bitmap file. The bitmaps are all 32 by 32 and there can be any amount of tiles in them in any number of rows or columns. I plan on the function taking the number of columns and the number for the tile say 5. Then I should be able to find the screen coordinates in pixels of the tile. Tile one would have a top of 0 a bottom of 32 a left of 0 and a right of 32. It seems easy but im having trouble any ideas? or did i not explain it well enough.
Last edited by abcdefg; Apr 19th, 2005 at 03:00 PM.
-
Apr 19th, 2005, 06:09 AM
#2
Frenzied Member
Re: Looking up tiles
visual basic code:
Dim TileWidth As Integer
Dim TileHeight As Integer
Dim ImageWidth As Single
Dim numTilesX As Integer
Dim X As Single
Dim Y As Single
Dim i As Long
TileWidth = 32
TileHeight = 32
ImageWidth = 128
numTilesX = ImageWidth / TileWidth
i = 9
X = (i Mod numTilesX) * TileWidth
Y = (i - X / TileWidth) / numTilesX * TileHeight
-
Apr 19th, 2005, 12:27 PM
#3
Thread Starter
Addicted Member
Re: Looking up tiles
One quick question what is the i variable for and why is it set to 9? Also It must be a rectangle so would I just use the Y and X again but say add 1*32 to get the right or bottom edge of the tile?
Last edited by abcdefg; Apr 19th, 2005 at 03:02 PM.
-
Apr 19th, 2005, 04:45 PM
#4
Frenzied Member
Re: Looking up tiles
"I plan on the function taking the number of columns and the number for the tile say 5."
The i variable is that number... I just used 9 instead...
I don't understand the other question. Try explaining again...
-
Apr 19th, 2005, 05:49 PM
#5
Thread Starter
Addicted Member
Re: Looking up tiles
The other question was just that I need the rectangle for the texture in the image. The left top right and bottom of the image. So the first rectangle would be 0,0 for the top and left and 32 32 for the bottom and right.
-
Apr 20th, 2005, 05:08 AM
#6
Frenzied Member
Re: Looking up tiles
X, Y = Upper left corner of the tile
X + TileWidth, Y + TileHeight = Bottom right corner of the tile
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|