16x16 tiles are too big on the screen and 8x8 tiles dont let me have enough detail in characters. Are 12x12 tilemaps possible? If so, is there an extension for it?
nope, i’m afraid not.
the supported tile sizes in our physics engine (32, 16, 8) are carefully chosen because they are powers of 2. the reason that matters has to do with how computers represent numbers and how fast different math operations are.
say i have a position (x, y) and i want to figure out what row/column that point is in inside our tilemap. it’s actually a pretty simple equation:
column = Math.floor(x / tileWidth)
row = Math.floor(y / tileWidth)
the problem is that different math operations on your computer take different amounts of time, and division is one of the slowest. our physics engine has to do this calculation hundreds if not thousands of times each frame, so using a slow operation like division really gums up the works.
so how does the tile width being a power of 2 help with that? well, numbers on computers are represented using binary (base 2) and as a result we can use a neat trick to make division super fast. if you take all of the bits of a binary number and shift them to the right by one digit, it’s the same as dividing by 2 and using floor on the result. bit shifting is super, super fast so it makes our physics engine way more efficient.
An example
if you’re not used to working with binary numbers this can seem confusing, but this is actually a rule you can apply to numbers in any base. to clarify things, let’s look at a number in base 10:
1234
say i were to shift all the digits to the right, i would end up with:
0123 (the 4 is cut off because it has gone off the 'edge')
this has the same result as dividing by 10 and chopping off the remainder!
tldr: by making all of the tile widths powers of 2 our physics engine is way faster but unfortunately that means it’s not possible for us to support widths that are not powers of 2 (like 12)
Alr, thanks!