0

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

j08691
  • 204,283
  • 31
  • 260
  • 272
Bruno Filip
  • 139
  • 8
  • 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? –  Dec 15 '17 at 17:16
  • *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 Dec 15 '17 at 18:55
  • 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? –  Dec 15 '17 at 20:10
  • Yes, thats what I'm asking – Bruno Filip Dec 16 '17 at 16:42

1 Answers1

3

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 ]
      }
   ]
}
  • But that doesn't answer my question, i am trying to load textures as tiles. I can already save the map, I can load the names of the textures from the saved map, do wathever with that data, but my problem is images how do I get to these images – Bruno Filip Dec 15 '17 at 18:58
  • Generally textures for 2D maps are grouped together and stored in one file called a tile-map. This is done to increase load time by reducing the number of IO operations required - instead of loading all 20 tile textures individually, you can simply load one and then 'cut out' each texture in memory. I would recommend you follow a similar approach with your map editor instead creating a tile map as you go with the images the user has uploaded. This tilemap image can then be stored with the other map files. –  Dec 15 '17 at 20:40
  • You mean Tilesheet? I wanted to do that but it seemed simpler to make slots that can have tiletextures that cutting a texture into smaller ones – Bruno Filip Dec 16 '17 at 16:44