0 favourites
• 15 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
• How would I go about making an advance wars style grid? I have already made my map via tiling, but I was wondering how I would start to make each tile have their own variables, I'm guessing I would have to make a grid of some sort that is 16x16 but I'd hope I wouldn't have to do this manually through sprites or anything, would anyone be able to tell me where I could get started?

• You could use an array.

Let's say your map is 20x30 tiles, and that each tile could have up to 5 properties.

Then if you have an array of 20x30x5, let's call it "TileProperties", you could decide that, in this array :

• TileProperties.At(X,Y,0) = the defense of the tile at X,Y in the tilemap.
• TileProperties.At(X,Y,1) = the movement cost of the tile at X,Y in the tilemap.
• TileProperties.At(X,Y,3) = the property you want of that same tile at X,Y

...

To do this, once the map is loaded, you should check every tile to store the properties in the array. Something like this.

Once this is done, you can then know what is the property value for each property of each tile on the map with a single Array.At.

• I use something similar in my game, the way i do it, is by using several tilemaps.

So one tilemap are the terrain informations, meaning that this is where the map is actually drawn, stuff like grass, mountains, deserts, water etc.

Next there are a tilemap that holds road, rivers etc.

A collision tilemap that hold all informations about which tiles are impassable and how costly it is for a unit to move on a given tile.

There are some other tilemaps as well.

So what i can do, is simply use each tilemap to check certain things. For instant it is more costly to move in mountains than on grass. So ill check each tile during start of the game, and save these information to the collision tilemap. And then i just check for roads and if there are a road on a tile with mountain it will then use the road settings and not the mountain.

In my game, if i render the collision map it will look like this:

Now there are some tiles that are not added.... but the color goes from none to black, where red cost a lot, and black is impassable, such as water. So it works fine, and units prefer moving on roads, avoid mountains etc. And it gives a good amount of flexsability as you can add several different tiles on top of each other and just read the information from a given tilemap when you need it.

• Thanks for the replies I really love this community. <3 to everyone.

• You could use an array.

Let's say your map is 20x30 tiles, and that each tile could have up to 5 properties.

Then if you have an array of 20x30x5, let's call it "TileProperties", you could decide that, in this array :

- TileProperties.At(X,Y,0) = the defense of the tile at X,Y in the tilemap.

- TileProperties.At(X,Y,1) = the movement cost of the tile at X,Y in the tilemap.

- TileProperties.At(X,Y,3) = the property you want of that same tile at X,Y

...

To do this, once the map is loaded, you should check every tile to store the properties in the array. Something like this.

Once this is done, you can then know what is the property value for each property of each tile on the map with a single Array.At.

Sorry but when you say 20x30 do you mean 20x30 pixels per tile? Or 20x30 tiles per map?

• What he means is that if you have a tilemap that are 20x30, so 20 tiles in X direction and 30 tiles in Y direction. Then you should make an array that are 20x30 as well, the Z value (the 5) are the one that holds the information for that tile, in his example it can hold 5 different information, if you need more you just increase it to whatever you need.

An example:

If the tile in your map at position (1,1) is a rock. Then the array at (1,1,0) could hold rock.

The reason he use 5 is simply if you need a tile to store several information. So lets say that this tile also have a defence value of 2.

Then your array would be like this:

Array(1,1,Rock)

Array(1,1,Defence value 2)

So the first two numbers in the array refers to the position of a tile in your tilemap.

• nimos100 thanks for explaining it more clearly, that's exactly what I meant

All those 20, 30 and 5 are, of course, variable. You can have how many properties you want on each tile, just increase the 5 I used.

Having multiple tilemaps like Nimos100 said is also a nice solution, as it is easier to read/write in the events maybe. I'm not sure it is best performance-wise, but as the map isn't drawn, I don't see any problem. For a debug purpose it's a lot better this way (as you showed us).

To simplify my solution, you could also use some global constants to represent the property you use in the array.

Let's say "NAME" = 0, "DEFENSE" = 1, and "WALKABLE" = 2, then you could get a property for the tile at the position X,Y using :

Array.At(X,Y,DEFENSE)

It's more like a define in any other language, but you get the idea : simplify the writing/reading

• [quote:2vimrvlb]Having multiple tilemaps like Nimos100 said is also a nice solution, as it is easier to read/write in the events maybe. I'm not sure it is best performance-wise, but as the map isn't drawn, I don't see any problem. For a debug purpose it's a lot better this way (as you showed us).

Performance wise I think using arrays are faster, but in my game as its automatic turn based or what to call it, meaning that each time the player does something it will do a turn. So I don't have to update my tilemaps all the time. but only when something trigger some change, which would be to one tile at the time.

Another benefit is that the player can hide and show different things, like showing the territory of the different empires, building areas and so on. Since they are separated showing and storing these information in tilemaps make it very easy to work with. So for me I don't really get a lot from using arrays over just using the tilemaps them self, as the performance is not really affected a lot by having several tilemaps.

• So I'm starting to understand arrays a bit more but still feel like a complete noob, I tried setting some text every tick to "TileProperties.At(Mouse.X,Mouse.Y)" but I am assuming that it's the wrong way as it stays at a constant "0" I'm pretty much just going by trial and error at this point xD

• Ok so as I progress I am starting to see a bit of an issue, I need individual spaces to each have their own separate variables, even though they may be the same tile, I wish there was just a way to make a grid or something that covered my layout but it's seeming that I will have to make one manually.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Is this the kind of thing your looking for?

https://www.dropbox.com/s/r93yk7anwcwi3g3/tileinfo.capx

• So I'm starting to understand arrays a bit more but still feel like a complete noob, I tried setting some text every tick to "TileProperties.At(Mouse.X,Mouse.Y)" but I am assuming that it's the wrong way as it stays at a constant "0" I'm pretty much just going by trial and error at this point xD

Yeah that will most likely give you a 0

The reason for this is probably because there are no data stored at the given position.

As you move the mouse around, you constantly update where in the array you are reading data from. So if your layout is 1000x1000 pixels. And you move the mouse around you will look up data in the array based on pixels rather than tiles. This is because each tile in the tilemap is not 1x1 pixel big, but might be 32x32 or whatever you have chosen.

If we assume that each tile is 32x32, then the array at position (0,0) would actually be all pixels from 0-31, 0-31.

So what you have to do in order to get "TileProperties.At(Mouse.X,Mouse.Y)" to work, is to convert the mouse-position into a tile position. which is fairly easy, using the tilemap function PositionToTile(X,Y).

So your function should look like this:

TileProperties.At(Tilemap.PositionToTile(Mouse.X), Tilemap.PositionToTile(Mouse.Y))

• Thanks again guys lifesavers you are.

• Is this the kind of thing your looking for?

https://www.dropbox.com/s/r93yk7anwcwi3g3/tileinfo.capx