Can someone tell me why this grid is overlapping?

I was building a grid today with 32x32 rectangles, each having a 1 pixel spacing.
However, as long as I kept the spacing at 1px, the rectangles started overlapping each other every other 2 rectangles.

As soon as I increased the spacing to 2px, the spacing between the rectangles was showing up as 1px in between.

Here is the code:

local grid = 8  
local gridSpacing = 1  
  
for iX = 1, grid do  
 local p = display.newRect( 0, 0, 32, 32 )  
 p:setReferencePoint( display.TopLeftReferencePoint )  
 p.x = ( ( iX - 1 ) \* pixelSize ) + ( ( iX - 1 ) \* gridSpacing )  
 p.y = 0  
end  

Can anyone tell me what’s going on?
The config.lua is set to 768 x 1024, letterboxed.
[import]uid: 86582 topic_id: 28903 reply_id: 328903[/import]

Hi there,

First a quick note: since the rectangles go from 0,0 to 32,32, they’re actually 33x33, not 32x32.

Does the overlapping issue you describe change depending on what device you’re simulating in the Simulator? If you’re simulating an iPad (which has the same resolution as your config.lua settings), I wouldn’t expect an issue. But if you’re simulating an iPhone, I would, because the scaling of 33 pixels from iPad resolution to iPhone resolution doesn’t result in a whole number of pixels, so it may not be able to achieve the pixel-perfect rendering you’re looking for.

When I run this code simulating an iPad (and setting pxelSize to 33, not 32), I don’t see an issue, but I do see it when I simulate an iPhone.

  • Andrew [import]uid: 109711 topic_id: 28903 reply_id: 116397[/import]