• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Making a tile collision system NOT to the power of 2

Hello! I've slowly been chipping away at a procedural generating game that uses tilesets and sprites to the dimensions of 24 x 16. To my understanding, all tile collision tutorials on youtube use the binary approach to snap your player object out of a tile. (using the bbox &~) Naturally, this approach doesn't work, so im curious of theres a workaround. What are your thoughts?
 

Rob

Member
Hello! I've slowly been chipping away at a procedural generating game that uses tilesets and sprites to the dimensions of 24 x 16. To my understanding, all tile collision tutorials on youtube use the binary approach to snap your player object out of a tile. (using the bbox &~) Naturally, this approach doesn't work, so im curious of theres a workaround. What are your thoughts?
If the tutorials use one variable for their calculations, use 2 instead (eg 24 for width, 16 for height)
 

TheouAegis

Member
I am pretty sure they don't ALL use bitwise math, because I rarely see bitwise math around the forums these days.

x&~15 is fundamentally the same as x-=(x mod 16), and (x div 16)*16, both of which can be used with non-power-of-two dimensions.
 
Top