Results 1 to 4 of 4
 03172013, 02:15 AM #1Member
 Join Date
 Mar 2013
 Posts
 1
 Rep Power
 0
 03172013, 03:16 AM #2Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 6,226
 Rep Power
 14
Re: Rendering 16x16 tiles, confused with the math behind it.
Java Code:public final int MAP_SIZE = 64; public final int MAP_SIZE_MASK = MAP_SIZE  1; ... int tileIndex = ((xx >> 4) & MAP_SIZE_MASK) + ((yy >> 4) & MAP_SIZE_MASK) * MAP_SIZE; pixels[x + y * width] = tiles[tileIndex];
For every bit you shift right, you are dividing by 2.
For every bit you shift left, you are multiplying by 2.
the & is a bitwise AND operation and the  (veritical bar) is a bitwise OR. In this case the former is to zero out unwanted Higher Order Bits.
so the tileIndex = xx/16 + (yy/16) * MAP_SIZE
Using bit manipulation sometimes makes things clearer. Here, the code author used mixed methods.
I recommend checking the web for binary or bit operations for a more in depth understanding of the subject.
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 03172013, 04:00 AM #3
Re: Rendering 16x16 tiles, confused with the math behind it.
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
 03172013, 04:02 AM #4
Similar Threads

Confused on how to start this Math program
By gnng in forum New To JavaReplies: 3Last Post: 04162011, 12:14 AM 
tiles problem
By rahulseven in forum Web FrameworksReplies: 1Last Post: 09012010, 02:04 PM 
Plotting Map Tiles
By RDReavis in forum Java 2DReplies: 2Last Post: 06062010, 07:16 PM 
struts tiles
By sasikumarm in forum Web FrameworksReplies: 0Last Post: 03272008, 02:36 PM 
Tiles in JSF
By Heather in forum SWT / JFaceReplies: 2Last Post: 06302007, 03:20 PM
Bookmarks