Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently rewriting some horrific code I wrote for a prototype and have stumbled right at the start! The game I'm working on revolves around directing light and there is a small ambiguity in regards to the way the grid is drawn:

enter image description here

Code wise, information about each node of the grid is stored in an int[,], the grid lines are drawn for debugging purposes. Currently there is nothing explicitly defined for the line thickness, i.e if you look at the pixels closely, the bottom and right lines are drawn in a way which means the grid is not centered on screen, it is one pixel out!

If you shrink the scale of the grid to each being cell being 4x4 pixels the problem is really obvious:

enter image description here

The red area is the cell; the lines show how I draw the grid lines and what the light beams travels across. Would it better to represent this as a grid of 3x3 pixel cells with a line thickness of 1?

Normally I wouldn't be bothered too much because this is really looking into it in a lot of depth, but since the lines of light themselves actually traverse these currently non-existing lines I thought it might be better to make the representation a more elegant! What do you think?

share|improve this question
How big is each tile assuming a blank grid. 4x4? – Justin Skiles Aug 23 '12 at 23:26
Currently 32x32 but that could go easily go up or down depending on the art style my friend comes back with! – Joe Aug 23 '12 at 23:32

Internally the game should handle the lines as zero-thickness. Thus the lines are between the grid cells. This applies to all logic and calculations of the game mechanism. When rendering, you need to decide how to adjust the lines to pixel based rendering. Usually the solution is to render the pixels that are bottom-right from the position of the logical line, just like you are currently rendering. One other option would be using antialiased lines with sub-pixel accuracy and render the line on both sides with 0.5 alpha, but this doesn't look as good when most lines are horizontal or vertical. If you are using the bottom-right rendering, you can enlarge the drawing canvas to bottom right by 1 pixel also to make the lines in the bottom and right edges visible as well.

It shouldn't really matter if you used 3x3 pixel cells with a grid between them, as this is only related to the rendering. It would just confuse the calculations.

share|improve this answer
Currently all my positions are stored in a Point anyway, and I use a method to convert the point values to positions whenever I need screen coordinates rather than array indexes. So whether or not this would increase workload... I'm not sure – Joe Aug 24 '12 at 18:55
It's not really about workload. You just need to make sure that if the points in the code represents points between the grid cells instead of the top-left pixels in the cells, it should be clear everywhere in the code. This means naming conventions and documentation. Otherwise there is a risk that the internal and rendering representations can get mixed together and lead to code that is harder to maintain. – msell Aug 27 '12 at 5:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.