#### Archived

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

# Scrolling tile world?

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

## 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 on other sites
The AND is used like a fast MOD, to give the remainder.

[edited by - Michalson on May 5, 2002 9:46:18 AM]

##### 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]

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631786
• Total Posts
3002350
×