0
votes

Okay everyone, I have a problem.

I am making a Map Editor for my 2D game.

Basically I have a "Slot" object, and it contains a "Tile" object (which belongs to slot and has a Texture). I have 2 Types of slots:

  1. Type is Pen Slots, when you press them and form pops up which you use to load an image for a tile anywhere on the computer. Last clicked tile is an active tile.

  2. Type is Map tile. They are 32x32 slots that are stacked next to each other an make it look like a map. When you have a pen and you clicked on it so its active, you can draw a map then, it copies pen slot texture to map texture.

Now I managed to save my map to a text file (for each tile -> Path.GetFileNameWithoutExtenson -> save map.txt). And I can load a text file to get saved names, BUT I DONT KNOW WHAT TO DO WITH TEXTURES, should I:

1. I would be using this Editor for my game, so I could put all my textures from the game inside some folder in Map Editor project, same textures same names that could work.

2. ????

Could anyone reccomend me if they can think of another way to load textures into Map slots ?

EDIT:

Lets say I have a 3 x 3 map and 3 textures as tiles:

sky sky sky sky grass sky dirt grass dirt

also texture names are also sky, grass and dirt, so its easy to store texture names in variables/array whatever when loading a map. But what about textures? What do I do with the images.

Lets say I use my map editor for 10 different games, I save a map as a map.txt file with texture names. I restart map editor and I want to load the map, it can load text given data fine, but what about images, how do I pass tiles from map editor to game

1
I'm having a hard time understanding your question. Correct me if I'm wrong, but you've created a map editor which allows users to create their own tiles (which have textures?), and use these tiles in creating a map (32x32 array of tiles?) - you're just unsure as to the best way of saving / loading these custom maps/textures? - user5986440
*Which allow users to choose an image from computer and load it into a slot, and use those images as tiles in map slots which is an array with tile width and eight 32x32 I am unsure about loading textures that are tiles, can get their name but not sure if I should also save each texture in map folder where the map.txt is - Bruno Filip
I'm still unsure as to what you're actually asking. You're not sure how you should store the tile textures the user has selected? Say the user creates a map with five textures, you're not sure how to store these for the game to then later use? - user5986440
Yes, thats what I'm asking - Bruno Filip

1 Answers

3
votes

When saving information it's generally best to segregate data as much as possible. This allows for easier maintenance in the future, and overall cleaner design.

In your case I would store each unique tile in an array, and simply have the map keep track of which tiles go where (through indexes into the tile array). This is the most common way tile maps are implemented in games.

How you actually keep track of the data on disc is entirely up to you, although I would recommend JSON as there are many libraries that make parsing it very easy. Although you could use serializable objects, or even write your own file format. For more information on reading / writing JSON files in C#, see this post.

An example of a test map stored to disc as JSON would look something like this:

{  
   "tiles": [  
      {  
         "id": 1,
         "hasCollision": false,
         "texture": "DirtPath.png"
      },
      {  
         "id": 2,
         "hasCollision": true,
         "texture": "DeadTreeStump.png"
      }
   ],
   "maps": [  
      {  
         "id": 1,
         "name": "Test Map",
         "tiles": [  
            0, 0, 0, 0, 0,
            0, 1, 1, 1, 0,
            0, 1, 2, 1, 0,
            0, 1, 1, 1, 0,
            0, 0, 0, 0, 0 ]
      }
   ]
}