|
-
Dec 8th, 2001, 09:26 PM
#1
Thread Starter
Hyperactive Member
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
-
Dec 8th, 2001, 09:40 PM
#2
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.
-
Dec 8th, 2001, 10:13 PM
#3
Good Ol' Platypus
It would be a bit faster to:
VB Code:
For X = 0 to 1600 Step 16
For Y = 0 to 1600 Step 16
BitBlt blah blah, X,Y (tiles are 16pixels wide/tall)
Next Y
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)
-
Dec 8th, 2001, 10:41 PM
#4
Thread Starter
Hyperactive Member
hmm..
thanks for the STEP idea.. i gotta try that..
as for the other post.. yeah.. i already do that 
any other improvement tips?
-
Dec 8th, 2001, 11:00 PM
#5
If you can, try to remove the inner loop. Itll save a tiny bit of time(read, a few clock cycles).
Z.
-
Dec 9th, 2001, 01:11 PM
#6
Frenzied Member
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:
Dim X As Long, Y As Long
Dim DestX As Long, DestY As Long
Dim TileX As Long, TileY As Long
DestX = ViewX + ScreenTileX
DestY = ViewY + ScreenTileY
'Loop trough all tiles and draw them
For X = ViewX To DestX
For Y = ViewY To DestY
Blt imgTiles, Backbuffer, TileX, TileY, Map(X, Y).SrcX, Map(X, Y).SrcY, TileSize, TileSize
TileY = TileY + TileSize
Next Y
TileX = TileX + TileSize
TileY = 0
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
-
Dec 9th, 2001, 01:13 PM
#7
Frenzied Member
Something I forgot, TileSize is the size of the tile (duh) and ScreenTileX/Y is the width and height of the map, in tiles
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
|