[Project]Tiles and TileMaps

I want to make a tile-based world with array-based terrain heightfield support.

I want to load the tiles from a file like ,

 L L L L L L L L 
 L L L W W W L L
 L L L L L L L L 
 L L L L L L L L  
 L L L L L L L L  
 L L L L L L L L  
 L L L L L L L L  
 L L L L L L L L  

Where L is a grass tile and W is a rock tile,which the code will use to add models.

Now my query is how can i display such tiles like a grid, and later add heightfield property to it?

I did it easily by creating an image in JAVA by that kind of grid == splat image (TerrainQuad). That way you can assign texture to each different tile type. I also created the picture a little bit bigger and scaled it down == fuzzy pixels == no super sharp tile edges.

Similarly you can do a height map matrix and assign (AbstractHeightMap) it to the map. It is easiest if you want a little bit “griddy” look. Or you can use some noise algorithm. Or later load it in the IDE and edit it by hand.

Grid edges you need to do yourself either by using shaders (?) or creating a model for it dynamically. Or really just splat it in if you have textures to spare.

See the tutorials for texture splatting. It pretty much describes how this is done in code.


I think you should look at Tiled

to edit the map. Later you can import it into jme3 and display it with some kind of terrain.

@atomix I want random map generation feature in the game.So I think Tiled will not help much.Can you share what you did with Heaven RTS regarding tiles. There is no setup instruction in the tutorials page and so I cannot build and debug the game.

Yes, I know HeavenRTS is in un usable state right now. Hope I can fix it soon.

Regarding tiles, RTS game like Starcraft has sotisphicated algorithm to generate tile and block of tiles. In short, that job is not easy. What I want to do is at least generate pieces of premade block, than randomly arrange those block to make something visually fit with our games.

At least, I can share with you examples of JME3 loading tiled map and transform it to somekind of terrain. In my games, depend in what I want, I’ve transformed them into: “platformer game terrain”, “tiled page terrain”, “block like terrain”, “patch like terrain”, “board game”… and else. So it’s really flexible.

The most simple block of code you can find in:

I will try to create a much simplier example for Tiled loading because it seems like a topic that every one care about. :smile:

P/s: In Atom-Mini (suite for Desktop+ Mobile game development), I use guava to enable non-blocking load of assets and also their Base64. So Tiled loading is much cleaner, much shorter and can load on the fly without headache. I will also make a repo for Atom-Mini soon.

@atomix I was thinking about using the tile images, and painting them in the X-Z Plane according to the text file. This is a feature which have to be there to implement fog of war, which I plan to achieve by reducing the alpha value of the image. However, I think this will not allow me to add height-field, or can it? Can you give me the code to display the image in X-Z Plane?

I will give you, whenever I have more time bro. :smile:

About fog of war, I did it differenttly. I have a filter which will add a fog layer and a 32x32 grayscale simple texture to present the fog. Whenever my viewport move, it will extract the fog info of that viewport (it’s a 32x32 bitmap) and put in into the fog filter.


Check this.

I think I explain it clear enough for you to implement the “fog of war” that suite you need.

@atomix Can you please tell me in which package of heavenrts can I find the source for tilemap generation?
It would be helpful if you give me the examples for

“tiled page terrain”


To answer the question you asked me on my OpenRTS topic :

There are two differents sides on your interrogation : the mesh division, and the material

about the mesh, you have three solutions :

  • One mesh for all your terrain. it will be slow to draw if the terrain is big (many useless vertices out of the camera). It will be awfully slow to update when you will change relief (big mesh rebuild each time).
  • One mesh for each tile. It will be slow to draw if you have a lot of tiles in the screen at a time, because each tile will be a separate object to give to the graphic car and that’s bad
  • Parcels (my choice), I manage tiles by pack of 100. Less object to manage by the GC, and little part of the terrain to update at each relief change.

The second part is the material to apply. Whatever is your choice for the grid division in meshes, you will have to apply a material that should be :

  • multitextured
  • non repetitive

Multitexture is done with jMonkey splat texture material and is a tricky thing to understand and to compute dynamically.

Non repetitive is obvious if you apply different scales for the textures.

Of course, if you want to make it oldschool, meaning one texture for each tile (which I would not advise) then you have to have one mesh for each tile, with the appropriate textured material.

In that case, you’ll have to manage a huge set of textures that can assemble with each other, tile with themselves, and with variety to avoir repetition. It was a monstruous work for game artists at the time of 2D oldschool game and shouldn’t be considered in a 3D approach, especially for an indy project.

Hope it helps !


I think the package i give is clear enough for use. No?

Lemme explain a little bit about making tiles “paging”. If your game is big, to be clear contain a lot of “squares”. You may want to continuosly and automaticly load the tiles ahead whenever you come to the edge of the current loaded tiles.

Again, my code in HeavenRTS just load the Tiled map and procedure a Batch map out of it. And because it’s a 64x64 square only and static, I don’t make it paging. The paging behavior is nicely write in some JME3 libs. Endless terrain for example. As for my self, I write my own with special algorimth to optimize the bandwidth and the resource load at run-time. It’s not a generic method to use in every game. So I assume you don’t really need “paging” at all, if you not writing an MMO??