Skip to main content
gamedev.net
🔒 Locked

Map editor *VB

Started by cube_35768 Mar 23, 2003 at 4:03 PM 0 replies 500+ views
Original Post
cube_35768
cube_35768
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.
Wyrframe
Wyrframe
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.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.