dcahrakos Posted May 11, 2006 Posted May 11, 2006 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. Quote
Leaders Iceplug Posted May 13, 2006 Leaders Posted May 13, 2006 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 you'll have a picture that you can assign or draw to the ImageBox (assuming that an ImageBox is a picturebox) :). Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Leaders snarfblam Posted May 13, 2006 Leaders Posted May 13, 2006 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 picturebox's 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 I'm 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.