Results 1 to 6 of 6

Thread: Looking up tiles

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    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.

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    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

    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    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.

  4. #4
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    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...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    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.

  6. #6
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    Re: Looking up tiles

    X, Y = Upper left corner of the tile
    X + TileWidth, Y + TileHeight = Bottom right corner of the tile
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width