ImageTile manipulation

BlitzMax Forums/BlitzMax Beginners Area/ImageTile manipulation

It's not very clear what kind of 'tile' system you have in mind by your posting, but typically I find it easiest to use a two-dimensional array to keep track of the layout of a tile-based game.

For example, you can translate your screen position (=tile) to a slot in the array, where you can keep track of which tile to draw where.
If there is no tile, put use a -1 or something for the value. Any time a tiles changes, you need to figure out which position it was in, and update that location in the array accordingly to reflect the new value.

If you use LoadAnimImage to load the info into your 'fiftytiles'TImage, then you can address the various tiles by their frame number.

When drawing the screen, you would do something like this:

local Leveldata[15,10]

For y=0 to 9
   For x=0 to 14
      If leveldata[x,y] <> -1 Then
         DrawImage(fiftytiles,x*50,y*50,leveldata[x,y])
      End If
   Next
Next


The above assumes a tile width and height of 50x50. Obviously change this to reflect your tiles, and unless you want to start in the upper left corner of the screen with your tiles, add an X and Y offset to the drawimage stuff as well.

(BlitzMax has a built-in TileImage command, but since it only draws blocks of identical tiles, you will have to draw your tiles individually in this case.)