Archived

This topic is now archived and is closed to further replies.

Scrolling tile world?

This topic is 5703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m reading through 2 articles called "Tiling in DirectX" written by Martin Estevao. However I have run into a part of the code that I don''t fully understand. offset_x = world_camerax & (TILE_SIZE - 1); offset_y = world_cameray & (TILE_SIZE - 1); I understand the concept of the offset values, but I don''t understand the bitwise operation. Could someone please explain in english what is happening in the above code. It''s taken out of context, so you probably need to take a look at the original article as well. It can be found here, and it''s relatively short so people with experince with programming tile based games can probably just take a fast look and understand what the code above is doing. http://www.gamedev.net/reference/articles/article1242.asp Thanks a lot for your help! I hope that my next game will be a tile based one.

Share this post


Link to post
Share on other sites
Say you want the remainder of a power-of-two number (for example 32). The number one less than that power-of-two will have all 1s up until that point... e.g.,

00011111 = 31
and
00100000 = 32

Therefore, the bitwise 'and' will cycle through every number below that power-of-two: you have 0s in every position greater than or equal to the power, so those bits will never be set after the 'and'. Therefore, it acts as a quick modulus. The values will cycle (in your example) from the values [0..TILE_SIZE-1] inclusive.

[edited by - Alimonster on May 5, 2002 10:06:27 AM]

Share this post


Link to post
Share on other sites