• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Borax Kid

How to program tile transitions (C++/SFML)

14 posts in this topic

Hello ! (My first post on GameDev.net !)

I started creating a top-down 2D tile based game and i'm currently doing the map system side of the game. I already made several modules, such as loading the map, dividing it in chunks, and each chunk has its own Vertex Array which contains all the tiles in this chunk. This works pretty well, but for now, there is no tile transitions, as seen in this screenshot : tumblr_inline_nai7fdo1Vo1rxgxsk.png
What i want is that tiles have a variant texture when they collide a tile with a different ID (dirt/sand or sand/water for example, but i think you got it). I made a "test" texture (and removed the sand for now) : VGOHLW6.png
When i made this tiles i thought about first drawing the entire tile, and then, in another function, detect if it is needed to change the border, than if it is needed, taking a border and drawing it on the vertex array. It sounds simple but i can't figure out how to do it, i tried all the afternoon to do this, in verifying every tiles if they need borders with the one on their right, down, and down-right, to minimize the loop. This way, if the current tile and the tile on the right are different, it will draw the right border of the current tile, and the left border of the tile on the right.
It looks to me it is a kind of low resources use method to do it, but everything i have done so far is a buggy mess.

Any suggestions on how to do that ? I'd really appreciate it, thanks.

PS: I'm sorry if i made some grammar errors, english is not my native language.
0

Share this post


Link to post
Share on other sites

Typically, the transitions are part of the tiles themselves.

 

For instance, look in the top left of the following tileset. Notice how the grass and water meeting diagonally are part of the same tile. Same thing for sand meeting the grass, and the grass meeting the mountains.

 

zelda005.png

1

Share this post


Link to post
Share on other sites

Thanks for the responses !

Eck: Thanks for the links, they're really useful 

Servant: I thought about layers but only for objects (mostly trees), but putting the transitions in a layer is a really good idea, I'll try to implement it and give you feedback as soon as I can.

 

Thanks a lot.

 

PS: Shacktar: I don't want to have tiles with transitions directly in the tileset, what i want is the entire tile, and then the borders of the tiles, as shown in the link Eck gave, but thanks 

0

Share this post


Link to post
Share on other sites

A possible technique for what Servant describes is named texture splatting. It can be done with a manually generated map but also with a map derived automatically from the surrounding tiles. The latter process is described in detail in Charles Bloom's good ol' article here.

Edited by haegarr
2

Share this post


Link to post
Share on other sites

Texture splatting is definitely an option. I was just suggesting tiles with alpha transparency. happy.png

 

In my own 2D tile-based game, I use splatting (using 'mask' tiles), but sometimes simple transparency works just as well.

0

Share this post


Link to post
Share on other sites

Hi everyone, I changed my opinion and now each of my rendered tiles are divided in 4, which is pretty simple to do and it let me make transitions easily. Each tile now have 9 textures tiles (full, right, left, top, bottom, and 4 corners). I'm pretty happy with the result I have (even if the textures are ugly for now), I just wanted to let you know what I did.

 

The only con (cons ?) with this method is that all the borders have to be the same tile/texture (dirt in my case), or if I make different borders (like water/sand or rock/grass) I will be forced to place sand around water (but what if it's a river ? water in rivers collide with dirt and not sand) so I made dirt for all borders, and it looks pretty cool imo.

So thanks again, even if, after rethought, I didn't use any of your solutions, but it made me learn things so that's cool.

 

Servant: With the layer system, I thought to put trees in a layer drawn after the player, but what if the player is in front of the tree and not behind ? The tree will always be on top of him, how can I fix this ? Any idea ? Maybe drawing entities (player, monsters etc) and the layer with objects like trees from top to bottom, but drawing for all the lines : Player, trees, next line, player, trees, next line etc. ? Thanks in advance

0

Share this post


Link to post
Share on other sites

Hi everyone, I changed my opinion and now each of my rendered tiles are divided in 4, which is pretty simple to do and it let me make transitions easily. Each tile now have 9 textures tiles (full, right, left, top, bottom, and 4 corners). I'm pretty happy with the result I have (even if the textures are ugly for now), I just wanted to let you know what I did.

 

You might find you want more than just those. What about inside-turns?

 

Inside_turn.png

 

(And if you want to get more detailed, there are even more possible orientations - but those others are less-critical than corners and inside-corners)

 

Also, depending on your art style, maybe you can just make one corner and one inside turn, and one edge, and rotate them in SFML. It'd save ya alot of work, if it works with your art style.

 

The only con (cons ?) with this method is that all the borders have to be the same tile/texture (dirt in my case), or if I make different borders (like water/sand or rock/grass) I will be forced to place sand around water (but what if it's a river ? water in rivers collide with dirt and not sand) so I made dirt for all borders, and it looks pretty cool imo.


Rivers sometimes have sand on their banks also! wink.png 
 

A better trick is to make your tiles use actual transparency. Instead of assuming they'll be over dirt, you could make the grass edge tiles actually have transparency, so they can go next to any tile.

 

Servant: With the layer system, I thought to put trees in a layer drawn after the player, but what if the player is in front of the tree and not behind ? The tree will always be on top of him, how can I fix this ? Any idea ? Maybe drawing entities (player, monsters etc) and the layer with objects like trees from top to bottom, but drawing for all the lines : Player, trees, next line, player, trees, next line etc. ? Thanks in advance

Two possible methods:
A) Sort your objects (including the player) by 'Y' position, and draw them in order from least to greatest.
Or B) Draw the trunks of the tree on a different layer then the tops of the tree.

0

Share this post


Link to post
Share on other sites

You might find you want more than just those. What about inside-turns?

Yeah, I forgot to tell that there is 4 more 8*8 textures for each tiles that represents inside corners, you're right.

 

 

 


Rivers sometimes have sand on their banks also!  

… Yeah but hum… Yeah. So… Dirt. wink.png.

No for real, I think it's look pretty enough like it is now, maybe later I'll give another thought about this but for now, borders are only dirt. (But you're right about the rivers happy.png)

 

 


A better trick is to make your tiles use actual transparency. Instead of assuming they'll be over dirt, you could make the grass edge tiles actually have transparency, so they can go next to any tile.

With this method, I'll have to draw the colliding tile under the grass (or any other) tile, but if there is a map like this :

G-D

S-G

(G -> Grass, D -> Dirt and S -> Sand)

the corners of the grass will be half dirt and half sand, imo that won't look pretty.

 

 


Quote
Servant: With the layer system, I thought to put trees in a layer drawn after the player, but what if the player is in front of the tree and not behind ? The tree will always be on top of him, how can I fix this ? Any idea ? Maybe drawing entities (player, monsters etc) and the layer with objects like trees from top to bottom, but drawing for all the lines : Player, trees, next line, player, trees, next line etc. ? Thanks in advance
Two possible methods:
A) Sort your objects (including the player) by 'Y' position, and draw them in order from least to greatest.
Or B) Draw the trunks of the tree on a different layer then the tops of the tree.

 

Yeah, what I tried to define was the A method, I think I will go like this. I'll try to find a performance-friendly way to iterate through every objects (even if I don't think there will be thousands of objects, especially just on the view region).

 

Again, thanks for replying and taking some time to help those who need some.

 

Edit: I add a little screen of the current "game" : nxsmVlj.png

The dirt and grass in one of the last line are "cut" because borders with other chunks are checked and drawn when the map is created, but when I change a block, only the chunk in which the tile is is updated, but I'll resolve this later.

Edited by Borax Kid
0

Share this post


Link to post
Share on other sites

That looks very good! smile.png 
 

Yeah, what I tried to define was the A method, I think I will go like this. I'll try to find a performance-friendly way to iterate through every objects (even if I don't think there will be thousands of objects, especially just on the view region).


Pre-sort them. =)

Save your tilemap, but also save your object-map ontop of it. Your object-map contains a list of objects pre-sorted by their y position.

Then, you do this:

//Draw objects north of the player.
for every object with object.y < player.y
{
   drawObject();
}

//Draw the player.
drawPlayer();

//Draw objects south of the player.
for every object with object.y > player.y
{
   drawObject();
}

Since most graphics APIs make (0,0) be the upper-left corner of the image you are drawing, you actually need to sort by (object.y + object.height), because objects (like trees) might be taller than the player, and you're actually trying to sort by the bottom of the object (the tree trunk, the player's feet, etc...), not the top.

Edited by Servant of the Lord
1

Share this post


Link to post
Share on other sites

That looks very good! smile.png 
 

Yeah, what I tried to define was the A method, I think I will go like this. I'll try to find a performance-friendly way to iterate through every objects (even if I don't think there will be thousands of objects, especially just on the view region).


Pre-sort them. =)

Save your tilemap, but also save your object-map ontop of it. Your object-map contains a list of objects pre-sorted by their y position.

Then, you do this:

//Draw objects north of the player.
for every object with object.y < player.y
{
   drawObject();
}

//Draw the player.
drawPlayer();

//Draw objects south of the player.
for every object with object.y > player.y
{
   drawObject();
}

Since most graphics APIs make (0,0) be the upper-left corner of the image you are drawing, you actually need to sort by (object.y + object.height), because objects (like trees) might be taller than the player, and you're actually trying to sort by the bottom of the object (the tree trunk, the player's feet, etc...), not the top.

 

Yes, that'd work if there was only the player to render, but there will be entities like monsters or animals.

Edited by Borax Kid
0

Share this post


Link to post
Share on other sites

It works for anything as long as you sort them by their (y+height) position.

 

Though, in the case where you have a huge mix of things moving around, I'd probably make trees count as "entities", and then just sort the entire array of "entities" and draw them in one loop. The rest of the terrain could still be tiles.

 

Or else, you can move to the other (easier) solution:

Draw the trunks of the tree on a different layer than the tops of the tree.

  • Background layer 1 (water, sand, grass, whatever)
  • Background layer 2 (transition tiles)
  • Background layer 3 (bushes, tree trunks (the bottom part of the trunk, anyway), rocks, etc...)
  • Background layer 4 (anything else needed, like maybe flowers in the bush, or vines wrapped around the tree trunk)
  • <Player and other entities get drawn next>
  • Foreground layer 1 (tree shadows, wall shadows)
  • Foreground layer 2 (tree tops, so they get drawn OVER the player when he walks behind them, and other things like bridges the player walks under)
  • Cloud layer (cloud effects, rain effects, etc...) (This layer is not tiles, but one repeating semi-transparent image that scrolls horizontally and vertically)

 

It's the less-perfect way, but it works well enough most of the time, as long as most of your entities are consistent sizes.

 

 

But it's really not too hard to do it the "perfect" way (sorted the trees with the entities by y pos), if you wanted to put in a little more work to do it right.

Edited by Servant of the Lord
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0