Question

dcahrakos

Active member
Joined
Jul 18, 2004
Messages
25
Hi,

ive been wondering about this for a couple days now, so heres my question,

what would be the best way to assign certain tiles(16x16 image files) certain values, such as 00 01 02 03, etc and then display them in a text box? this is sort of a map editor.

so say I read data from a file, and I get 00 02 06 01 00 00 00 it will load the images assigned to those values, then put then in a row in the image box(and if it reaches the end of the top row on the image box it will go to the next row, for example
tile tile tile tile tile
tile tile tile
instead of just cutting off at the end of the image box


Thanks.
 
Do you want to display them in one text box or several text boxes?

For putting them in an imagebox, I would declare a separate Bitmap to draw the tiles to using Graphics, and then youll have a picture that you can assign or draw to the ImageBox (assuming that an ImageBox is a picturebox)
:).
 
Parsing the data should not be too complicated. If you want to stick it all in one textbox, you can divide the text into individual numbers using the String.Split method. You can use Int32.Parse to convert the strings to integers. If you want to parse them in hex, there is an overload that allows you to specify a number format. (You can also use TryParse if you want to avoid exceptions.)

As far as drawing the resulting image, there are options, depending on how complex things become.

If the grid size is relatively small and is a constant, and the number of tiles is small, you could use picture boxes and an array of System.Drawing.Bitmap objects, and based on the tile number entered, assign the appropriate bitmap as each pictureboxs image.

If things get bigger, you probably want to render to a System.Drawing.Bitmap using a System.Drawing.Graphics object (obtained through the Graphics.FromImage method). The Bitmap can be assigned as the image of a picture box. This GDI+ approach would probably suffice.

If you are using a large number of small tiles, rendering a real large image, or performance becomes an issue, tile-based graphics can be slow using GDI+, i.e. the System.Drawing.Graphics class (in fact, I actually resorted to writing my own blitting functions for the application Im writing now). If you need more speed you might want to consider trying out (the old school but more complicated) GDI using the Windows API.
 
Back
Top