Better way to create Tiles

I am making a small Pokemon-like game as I am very familiar with how it works. As of now if I want to add a new tile I have to create a whole class for it and this means that if I want to create even a small building I would need to create tens of classes for every tile.

I learned how to create my game’s basics from here https://www.youtube.com/playlist?list=PLah6faXAgguMnTBs3JnEJY0shAc18XYQZ

And even I know (I think) that this is a very bad way of doing this. Here is my code https://github.com/TheGamerPlayz/Pokemon

Does anyone know of a tutorial that guides you through rendering multiple tiles at one (I mean not having to place each individual tile for a building or similar structure) at a time.

You could use a Vertex Buffer Object or something like that to render it all in one call, but are you running into performance issues? How many tiles are you rendering? Even if you were rendering in the least efficient way possible, you should be able to render pretty much all the tiles you need without having any issues in performance.

I suggest not using one VBO for drawing tiles in mass with texture atlases (tile sheets). I would upload a quad to a vbo with texture coordinates (and indices if you so wish) and store it in a vao to call glDrawArrays or glDrawElements for every tile once a frame.
Much easier to do and you get all your shader’s work in the vertex over some in the fragment. You also avoid writing a function which generates vertices, calculates the proper texture coordinates, and create required indices for them.

It seems like you are on the right track of abstraction, but I think you are going about it wrong with actually caring what the tiles are called. Instead of having a GrassTile, lets just call it by the position it is in the texture atlas (tile set).

This: [icode]Tile[] tiles = new Tile[255];[/icode]
Becomes: [icode] int[] tiles = new int[255];[/icode]
Or you could put an int inside a Tile class, but do not make GrassTile, DirtTile, etc.

And when time comes to actually determine things about the tile type, like walk noise, you could do something like…

switch(getCurrentTile().getType()) {
case 1:
play(grass_walkNoise);
break;
case 2:
play(stone_walkNoise);
break;
}

Or even get clever like…
[icode]play(getWalkSound(getCurrentTile()))[/icode]
for something like
[icode]Sound[] walk_sounds = new Sound[tile_types.length];[/icode]

What you are saying makes perfect sense to me, but I do not know enough to re-create the way my entire game renders images. Do you know of any tutorials? I have been looking for around two days now and I can’t find one

that’s kinda how you learn game programming tho :slight_smile:
start tweaking things and see what it does…

you need to start crawling before you can walk, and learn walking before you can run

If a certain hurdle is to hard to take at this point, then focus on the things you can do and change, you’ll get better eventually

that’s how we all learn(ed)

and when you try to run before walk you fall on your face pretty face and its hilarious to others.

ThinMatrix has some good tutorials. He uses LWJGL2. His is based in 3d, but 2d is basically the same. Just with tiny modifications in VAO and projection matrix.

How mant tiles are you rendering that it’s causing you performance problems?

Any reason you are not using Libgdx https://github.com/libgdx/libgdx/wiki/Tile-maps. It’s all done for you. You can identify different tile types using properties, or even by using different layers.

I have tried LibGDX and there are no tutorials, no instructions, or anything that show you how to use it. The best I could do was install it.

Here is a link to a general libgdx tutorial if you’re interested : )
http://www.gamefromscratch.com/page/LibGDX-Tutorial-series.aspx

Here’s a tutorial sepecifically about tilemaps
http://www.gamefromscratch.com/post/2014/04/16/LibGDX-Tutorial-11-Tiled-Maps-Part-1-Simple-Orthogonal-Maps.aspx

I seriously recommend you give it another go, you won’t regret it. It can be a bit tricky to set-up for beginners, but once you overcome this hurdle its worth it. The second link that TheMeanMan posted shows how easy it is to render a tilemap using LibGdx. There are plenty of YouTube tutorials, Wiki pages, online tutorials to get started.

I might be missing something but I’m seeing quite a few episodes on how to load & re-use tiles in this video series?