Results 1 to 7 of 7

Thread: Best way?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482

    Best way?

    What is the best way to cycle through tiles for a tile-based game?

    currently i am using this method

    For X = 0 to 100
    For Y = 0 to 100
    bitblt blah blah, X*16,Y*16 (tiles are 16pixels wide/tall)
    Next Y
    Next X

    is that the best way/ fastest?

    just seeing if there are any tips to improve speed

  2. #2
    Zaei
    Guest
    Figure out the tile taht is in the upper left corner of the screen, and start your Bltting from that point. For example, say you had you 100x100 tile map, but the tile in the top left is at 12, 12, and you know that only 10 tiles will fit on the screen at once(just as an example), your loop would look like:
    Code:
    for i = 12 to 22
      for j = 12 to 22
        bitblt
      next j
    next i
    Have a variable for x, and y, and then just as the height and width of tiles on the screen.

    Z.

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It would be a bit faster to:
    VB Code:
    1. For X = 0 to 1600 Step 16
    2.     For Y = 0 to 1600 Step 16
    3.         BitBlt blah blah, X,Y (tiles are 16pixels wide/tall)
    4.     Next Y
    5. Next X
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    hmm..
    thanks for the STEP idea.. i gotta try that..

    as for the other post.. yeah.. i already do that

    any other improvement tips?

  5. #5
    Zaei
    Guest
    If you can, try to remove the inner loop. Itll save a tiny bit of time(read, a few clock cycles).

    Z.

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Well, I don't see how we could remove the inner loop

    Anyway, if you have the tiles in an array, here's how I optimized my loop:

    VB Code:
    1. Dim X As Long, Y As Long
    2.     Dim DestX As Long, DestY As Long
    3.     Dim TileX As Long, TileY As Long
    4.    
    5.     DestX = ViewX + ScreenTileX
    6.     DestY = ViewY + ScreenTileY
    7.    
    8.     'Loop trough all tiles and draw them
    9.     For X = ViewX To DestX
    10.         For Y = ViewY To DestY
    11.             Blt imgTiles, Backbuffer, TileX, TileY, Map(X, Y).SrcX, Map(X, Y).SrcY, TileSize, TileSize
    12.            
    13.             TileY = TileY + TileSize
    14.         Next Y
    15.        
    16.         TileX = TileX + TileSize
    17.         TileY = 0
    18.     Next X

    See, no slow multiplications

    ViewX/Y is the coordinates of the screen (top/left). The map's SrcX/Y are the coordinates of each tile in the tiles image. This blt function is a wrapper function but you get the idea
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Something I forgot, TileSize is the size of the tile (duh) and ScreenTileX/Y is the width and height of the map, in tiles
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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