Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1026899 Posts in 41180 Topics- by 32787 Members - Latest Member: ixhi

July 26, 2014, 03:10:05 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Tile/Map-Based Game Techniques: Handling Terrain Transitions
Pages: [1] 2 3 ... 5
Print
Author Topic: Tile/Map-Based Game Techniques: Handling Terrain Transitions  (Read 23486 times)
nikki
Level 10
*****


View Profile Email
« 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

Valaam0
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 Email
« 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 Email
« 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 Email
« 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 Email
« 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
Gimym JIMBERT
Level 10
*****


Feminism is back!


View Profile Email
« 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


ILLOGICAL, random guy on internet, do not trust (lelebĉcülo dum borobürükiss)
Ed
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 Email
« 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
Pages: [1] 2 3 ... 5
Print
Jump to:  

Theme orange-lt created by panic