1
\$\begingroup\$

I have a game, and I have a level editor where you can build your level from blocks. Blocks positioned in cells. So blocks can have no neighbours or have one or few neighbours. My problem is that I need to put appropriate texture to block, based on block position related to another blocks. Is there some specific algorithms or methods that can help me?

I want it to update textures after adding/moving/deleting each block so it should be fast.

Levels can look like

- - - - - - - - - - - - - - - 
|                            | 
|             |- - - |       |
|             |- - - |       |
|                            |
|         - - - - -          |
|         |       |          |
- - - - - |       | - - - - -|
\$\endgroup\$
2
\$\begingroup\$

Use a bitmask to determine which graphic you want to use, see this article When you have neighbouring blocks of the same kind, simple change the bitmask and this bitmask is used for drawing the Tile. http://www.angryfishstudios.com/2011/04/adventures-in-bitmasking/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.