Archived

This topic is now archived and is closed to further replies.

Map editor *VB

This topic is 5381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a map editor for a simple 2D game, and I came across a problem. I was going to have this code for all 144 image boxes: Private Sub Image1_Click() If aLoad Then Set Image1.Picture = LoadPicture("C:\Chipset\Grass.bmp") ElseIf bLoad Then Set Image1.Picture = LoadPicture("C:\Chipset\GreyWall.bmp") ElseIf cLoad Then Set Image1.Picture = LoadPicture("C:\Chipset\Mud.bmp") ElseIf dLoad Then Set Image1.Picture = LoadPicture("C:\Chipset\DarkRoad.bmp") End If End Sub That only allows 4 tiles per image box so far, and with all 144 image box''s, that will be a ton of code for only 4 tiles. Is there an easier way to do this? Thanks.

Share this post


Link to post
Share on other sites
First off, I''ve tried that before. It is what every VB wanna-be-a-game-programmer dreams when they''ve been programming for less than a month or five. So, I''m going to put you through a few simple paces...

First, delete every one of your ImageBox controls. Replace them with one large PictureBox. Make sure the AutoRedraw property says "True", and the ScaleMode property is set to "3 - Pixels", and then fiddle around with the size of the PictureBox until it is large enough to show, let''s say, 12 by 12 (sq. root of 144) of your tiles (however big those tiles are). Name this picturebox "MapView".

Next, make 4 more pictureboxes, with the AutoResize and AutoRedraw properties set to "True", and Visible set to "False". Name these pictureboxes "MapTile", and make a Control Array (you''ll end up with MapTile(0), MapTile(1), ...)

Now, create a new Private function in the form, and call it "Redraw". Go to the Declarations section, and create an array of Integers, called "MapData". Make it at least 12 by 12, and two-dimensional.

Make a CommandButton, call it "cmdRedraw", and put in the code shown below...

And last of all, we have to load our graphics into the MapTile PictureBoxes.


  
Private MapData(1 to 12, 1 to 12) As Integer

Private Const TileSize As Integer = 32 '' Or Whatever...

Private Sub Redraw()
Dim X As Integer, Y As Integer

For Y = 1 to 12
For X = 1 to 12
MapView.PaintPicture MapTile( MapData(Y,X) ).Picture,((X-1)*TileSize), ((Y-1)*TileSize), TileSize, TileSize, 0, 0, TileSize, TileSize
Next X,Y

MapView.Refresh
End Sub

Private Sub cmdRedraw_Click()
Call Redraw
End Sub

Private Sub Form_Load()
Set MapTile(0).Picture = LoadPicture("C:\Chipset\Grass.bmp")
Set MapTile(1).Picture = LoadPicture("C:\Chipset\GreyWall.bmp")
Set MapTile(2).Picture = LoadPicture("C:\Chipset\Mud.bmp")
Set MapTile(3).Picture = LoadPicture("C:\Chipset\DarkRoad.bmp")
End Sub



Until you learn how to change the contents of the MapData array, you will be looking at a 12x12 grid of whatever is in "Grass.bmp".

Now, once you''ve done all this, go out and look for tutorials that teach you the fundamentals and theories behind what I just wrote.

Share this post


Link to post
Share on other sites