Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411426 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 10:05:03 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Tile/Map-Based Game Techniques: Handling Terrain Transitions
Pages: [1] 2 3 4
Print
Author Topic: Tile/Map-Based Game Techniques: Handling Terrain Transitions  (Read 69107 times)
nikki
Level 10
*****


View Profile
« on: December 14, 2009, 07:17:32 AM »


Hello,

i am trying to implement a tile transition.
i've found this handy article http://www.gamedev.net/reference/articles/article934.asp

the thing i don't fully grasp is the bitwise technique they use.
i believe checking each cell in a complicated if, elseif way for 32 different posibilities is not exactly the way to go, and thats why i suspect the usage of bitwise things, but i don't get it, 

Has anybody here had some experience in a technique like this ?, and could you explain the neighbour checking ?
Logged
st33d
Guest
« Reply #1 on: December 14, 2009, 08:02:31 AM »

Personally I'd do it the if/else way and just pre-cache the result.

Accounting for every possible transition between tiles is going to enter massive if/else territory whether you like it or not. Perhaps the better solution would be to reduce the number of possible transitions.
Logged
Sam
Level 3
***



View Profile WWW
« Reply #2 on: December 14, 2009, 10:54:28 AM »

edit An expanded version of this post is available at my site here. /edit

The bitwise technique basically does the same as a huge if/else statement, but saves on typing.

Much easier to first think of it first for a map with just two types of terrain - let's say rock and open air.

A simple map might look like this, with the filled tiles being where there's rock:



The key to the bitwise method is to assign a value to each tile depending on its neighbours.  For this example let's use the following values:



We visit each tile that is meant to be filled with rock, and examine its immediate neighbours to come up with a number for that tile.  If the tile directly above this one is also filled then the number is 1.  If the tile directly above AND the tile directly below is filled, then the number is 1 + 4 = 5.

Here's that tile map filled out with the correct numbers.



The clever bit is we can now directly convert those numbers into graphical tiles, so skipping having to write a huge if/else statement.  Here is a tileset, laid out in the order matching the valuing system we picked:



See how each tile graphic matches what would be expected of its corresponding number?

Now our game can just look at the number calculated for each filled tile, and pick out the correct tile to place there:



It would be the same principle even if you want to consider diagonal neighbours, or more varied types of terrain.  You'll just end up with a larger range of numbers.

The reason it's referred to as bitwise is because the values we're assigning to neighbouring tiles follows the same 2^n pattern as binary numbers.
« Last Edit: January 26, 2010, 01:03:55 PM by Salt » Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #3 on: December 14, 2009, 11:38:39 AM »

I nominate this to be the most helpful thread response ever.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Aquin
Level 10
*****


Aquin is over here.


View Profile WWW
« Reply #4 on: December 14, 2009, 11:41:52 AM »

Yeah, this is pretty damn handy.  Bookmarked!  Smiley
Logged

I'd write a devlog about my current game, but I'm too busy making it.
AdamAtomic
*BARF*
Level 9
*


hostess w/ the mostest


View Profile WWW
« Reply #5 on: December 14, 2009, 11:48:00 AM »

thank you for the wisdom and clarity of thought Grin  very cool!
Logged

cup full of magic charisma
nikki
Level 10
*****


View Profile
« Reply #6 on: December 14, 2009, 01:38:52 PM »

While you were making that GREAT little tutorial, i went deep in the google power and learned by myself,
when i figured the binary business and the careful laying out of your tilemap out.

it is a brilliant technique , instead of writing endless if elseif (and nested aswell) mumbo jumbo , i only need 4 or 8 if statements , you add the outcomes and voila your tilenumber !

It felt so great i started drinking beer, and now hav written an scrambled post  Beer!
Logged
AdamAtomic
*BARF*
Level 9
*


hostess w/ the mostest


View Profile WWW
« Reply #7 on: December 15, 2009, 10:22:08 PM »

Ok rolled this into flixel.  I also built an alternate 12-tile variant that doesn't handle 1-tile wide or 1-tile tall solid areas, but DOES do interior corners.  Is handy if you're doing zelda or RL instead of cavestory or mario Smiley
Logged

cup full of magic charisma
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #8 on: December 17, 2009, 08:43:07 AM »

The greatest most effective short tile tutorial i have ever read... Shocked Beg
It solve one of my concern with 3D tile and i also figured that i could use bit on diagonal to distinguish between a turn and a solid corner... Noir

In fact i works with any isotropic shape tile system, as long as yout correctly tag bitwise neighbor cell  Wizard

Officially awesome
Logged

shrimp
Level 5
*****


View Profile WWW
« Reply #9 on: December 19, 2009, 02:11:16 AM »

Good stuff! Also, Gyorgy Straub used this for some tiles for Assemblee - here
Logged

increpare
Guest
« Reply #10 on: December 30, 2009, 07:10:22 PM »

Oh, I never thought of doing it that way before.  Nice : D
Logged
Laremere
Level 5
*****



View Profile
« Reply #11 on: December 30, 2009, 08:55:56 PM »

That is an amazing technique, thanks a ton.
Logged

If a tree falls in the forest and no one is around to hear it, is sound_tree_fall.play() called?

"Everything that is really great and inspiring is created by the individual who can labor in freedom."
-Albert Einstein
Parthon
Level 1
*


View Profile
« Reply #12 on: January 07, 2010, 06:13:50 PM »

I used this same technique in Sim Cavern and it works really well. I ended up with a 4bit, 16 tile internal wall system that was very easy to work with, as well as nice and dynamic.

I'm working on a corner based 4bit x 4 system. It would require 64 x 1/4 size tiles to draw though, which may be a bit much. It would mesh a bit better though.
Logged
deadeye
First Manbaby Home
Level 10
*



View Profile
« Reply #13 on: January 09, 2010, 02:56:56 AM »

This is ace, thank you Salt Smiley
Logged

tweet tweet @j_younger
pgil
Guest
« Reply #14 on: January 09, 2010, 07:30:31 AM »

Wow, this is so simple. I got it working in Game Maker in about 2 minutes. Thanks, Salt  Beer!
Logged
gambrinous
Level 4
****


Indie Game Developer


View Profile WWW
« Reply #15 on: January 13, 2010, 04:11:33 AM »

ooo this is a nice explanation, bookmarking!
Logged

Eendhoorn
Level 6
*

Quak


View Profile
« Reply #16 on: April 14, 2012, 07:09:29 AM »

Bit of an old topic, but this deserves some attention :D
I was looking at this thinking this is one of those things that sound like it should work easily, but require alot of tweaking. But I worked on this for about 2 hours yesterday and it works perfectly.

However, there seem to be some situations where you can't solely depend on this technique:


Both are grass transitions, but they need to respond differently according to their surrounding tiles. There is no way to work around this then by using if statements right?

I could sort of see this working with different values for the surrounding tiles, water having higher numbers values than sand for example. But I am nowhere near genious enough to come up with an elegant solution for that  Droop
Logged

Henry141
Level 0
*


View Profile
« Reply #17 on: April 16, 2012, 12:03:11 PM »

Well, omgnoseat, this can easily be expanded to supporting that.

Just have the standard 1 2 4 8 for the four water tiles around the grass tile, but then carry on the progression for the four sand tiles, so they would be 16 32 64 128. This should still generate a completely unique number, this time between 0 and 240, and so you should be able to support 8 different textures in a standard 32 bit integer,  and there are probably other workarounds too.
Logged
Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #18 on: April 17, 2012, 12:10:15 PM »

This article does a good job at looking at all of the different types of connections that you would want from a binary tilemap.

To get perfect inner and outer corners, you need 47 tiles (unless you don't care about inner tile [15 in Sam's example]).

Logged
Eendhoorn
Level 6
*

Quak


View Profile
« Reply #19 on: April 17, 2012, 02:24:10 PM »

Thanks for the replies guys, was exactly what I was looking for!

This article does a good job at looking at all of the different types of connections that you would want from a binary tilemap.

To get perfect inner and outer corners, you need 47 tiles (unless you don't care about inner tile [15 in Sam's example]).

I'm currently looking into "the blob" method which is mentioned in the article, but bitwise operations are not mentioned Sad
Which values would the 4 corner tiles need to implement this method?

? | 1 | ?
8 | # | 2
? | 4 | ?
Logged

Pages: [1] 2 3 4
Print
Jump to:  

Theme orange-lt created by panic