2D Map Editor

BlitzPlus Forums/BlitzPlus Beginners Area/2D Map Editor

A 2d map is a 2d array, it might be better to use a bank tho.

If a side of your map is bigger than that side of your screen (higher, wider, or both) then you can only display a part of your map, the size of your screen (or the size of the canvas you're using to display the map).

Here are typical variables you need:

- tilewidth
- tileheight
(for example 32x32 for a single tile)

- xtiles
- ytiles
(for example 16x12, giving you a 512x384 map using those 32x32 tiles)

- xoffset
- yoffset
(if the map is bigger than your display, then these vars store your position)

- currentx
- currenty
(the vars containing on which tile your mouse is at the moment, I typically have the visual coordinates in these, without adjusting them with xoffset and yoffset, so using the earlier mentioned variables, these vars would contain 0..15 and 0..11)

- currentlocation
(calced: (currentx+xoffset) + (currenty+yoffset)*xtiles), with this you know where to poke/peek in case you're using a bank)



Additionally there's a "palette" with tiles you can draw with, this could be represented in quite the same way as that map, with tilewidth and tileheight for the tiles, xtiles and ytiles for the dimension of the palette, and xoffset and yoffset when your palette is bigger than the canvas it's in. An extra variable is currenttile, which holds the selected tile in your palette. Make sure the map editor has access to this currenttile variable.

What you then do is check for the right events in the map editor. If you have the mousebutton down ($201), set a variable like 'LMD' to '1'. Next check for mousemovement ($203), if this is going in and LMD is '1', then you are drawing your currenttile into your map. To put this currenttile into your map use the map variables to put the value of currenttile at the right place.

That's roughly all to it really, basic map editors aren't that hard to do.