Question

I'm using tiled map editor to make 2d maps for making a game with pyglet. The tiles are numbered and saved to a .tmx file. The tiles numbers start at 1 and keeps ascending but when you flip a tile that tile number is changed with bitwise so when you parse the data you know how to flip it. The document explains how to break it down [here] (https://github.com/bjorn/tiled/wiki/TMX-Map-Format#data) under tile flipping. I have no idea where to even start, I've never used bitwise. I looked up bitwise for python and read about & | << >> bitwise operators and played with them in the interpreter but I still don't understand how to break down the tile numbers to get the data. One of the numbers I have is 2684354578 can someone show me how to do this?

Was it helpful?

Solution

The numbers are 32 bits wide. The upper 3 bits number 31, 30 and 29 identity the flipping information.

You can force these 3 bits to zero by expression

result = number & 0x1FFFFFFF

The prefix 0x means it is a hex number. Each digit represents 4 bits using the values 0 till 9 and A till F. The number is thus 3 zeros followed by 29 ones.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top