Skip to main content
7 events
when toggle format what by license comment
Mar 12, 2020 at 14:47 comment added Ruadhan2300 I'm not very up on Bitwise operators, but as far as I can understand, it's essentially using the bitwise operator to help add the left-to-right indexes of each row to the top-to-bottom indexes. I believe it's directly equivalent to (tileY*GridWidth + tileX) but maybe deals with some subtleties I've not noticed. Just another way to do do things. Remember that Bitwise operators like this are effectively performing binary arithmetic behind the scenes, so you can exploit that behaviour in interesting ways.
Mar 12, 2020 at 14:44 comment added David Rees Okay, I see that now that I am looking at it, but my last question is about this line of codeint tileIndex = (xTile &(MAP_WIDTH_MASK)) + (yTile &(MAP_WIDTH_MASK))* MAP_WIDTH obviously its giving you the tileIndex that you are on by giving you the (x,y) coordinates as I can see the formula being [x + y* width] but what is the & for and why is it ANDing with the MAP_WIDTH_MASK
Mar 12, 2020 at 14:38 comment added Ruadhan2300 each tile is a grid of pixels which the sprite-sheet is being mapped onto.
Mar 12, 2020 at 14:36 comment added Ruadhan2300 The tiles are being iterated in two nested For Loops, one for the Y axis, the second for the X axis, essentially it's going through it row by row. Then inside that, it handles the individual pixels of each tile in two more nested for-loops for their own tiny grids which handle the intervening pixel positions that the bigger loops aren't dealing with.
Mar 12, 2020 at 14:32 vote accept David Rees
Mar 12, 2020 at 14:32 comment added David Rees Thanks for the quick answer, that makes more sense now, where exactly would the line of code be to tell it to loop the tiles as I understand that the for loop just iterates through all the tiles? I understand the & sign but I don't understand what it is used for in this context.
Mar 12, 2020 at 14:20 history answered Ruadhan2300 CC BY-SA 4.0