Bitwise Tilemaps

Here is a technique that I have been wanting to use in my projects for a while: Bitwise Tile Generation. It’s usefull to add some flavor to your world/level.

Basically you use a full tileset for the grass or platformer tiles in your game and you calculate if there are similair tiles next to each other to change the sprites. If you don’t have to calculate corners you just have to check 4 tiles each time for 16 different combinations.

Bitwise 1

Bitwise Tile Generation

If  you only have a tile on top you will use sprite 1 in the middle. But it you have a tile to the right and on the bottom you would use sprite 6. There are 16 different combinations from no tiles (0) to all tiles(15).
The reason why this technique is called Bitwise is because you’re basically using bits to check if there is a tile or not. 0000 translates to 0 or no tiles. And 0001 would be a tile on the top and so on.

But what if you would like to check the corner tiles as well?

Bitwise 2

Bitwise Tiles with Corners

Wel you just need to use more bits to check every possible combination. With corners you will have a full byte with 256 possible combinations from 00000000 to 11111111.

It’s a very usefull technique to use and it saves you a lot of time compared to building the world manually!

Source/Extra links:
Saltgames blog: Forum post:

Leave a Reply

Your email address will not be published. Required fields are marked *

nine − seven =

This site uses Akismet to reduce spam. Learn how your comment data is processed.