Making nice brick wall

Hi all!  :slight_smile:

Can you give me a hint how to make nice brick wall (like one on the attached picture).

So if I make it like this:

for i = 1, ((screenHeight + brick.height) / brick.height)) do

      for j = 1, ((screenWidth + brick.width) / brick.width)) do

                brick = display.newImage(“brick.png”)

                brick.x = (screenLeft - brick.width) + (brick.width) * j   -------- ScreenLeft is a constant

                brick.y = brick.height * i

                bricks:insert(bricks, brick)

      end

end

I get an even wall with bricks in every next row evened with previous row, and so on…

I do not want that, I want them to look like on the attached picture  :slight_smile:

So first row should be evened with third row, and second row should be evened with fourth row…

I want the bricks to fill entire screen.

Tnx!

Goran

Would something like this work? It uses the modulo operator to detect if the row number is odd or even and then shifts the row bricks accordingly

for i = 1, ((screenHeight + brick.height) / brick.height)) do

      for j = 1, ((screenWidth + brick.width) / brick.width)) do

                brick = display.newImage(“brick.png”)

                if i % 2 == 0 then – even row

                     brick.x = (screenLeft - brick.width) + (brick.width) * j   -------- ScreenLeft is a constant

                else --odd row

                     brick.x = (screenLeft - brick.width) + (brick.width * 0.5) * j   -------- stagger by half a brick width

                end

                brick.y = brick.height * i

                bricks:insert(bricks, brick)

      end

end

Hi jerejigga,

It does not work…

In even rows bricks are stacked…

I will play around with this more  :slight_smile:

Tnx.

Hi jerejigga,

When you play around with x-es in even and odd rows everything turns out OK!

Many thanks!

That’s great! I am glad it worked it worked out for you!

Would something like this work? It uses the modulo operator to detect if the row number is odd or even and then shifts the row bricks accordingly

for i = 1, ((screenHeight + brick.height) / brick.height)) do

      for j = 1, ((screenWidth + brick.width) / brick.width)) do

                brick = display.newImage(“brick.png”)

                if i % 2 == 0 then – even row

                     brick.x = (screenLeft - brick.width) + (brick.width) * j   -------- ScreenLeft is a constant

                else --odd row

                     brick.x = (screenLeft - brick.width) + (brick.width * 0.5) * j   -------- stagger by half a brick width

                end

                brick.y = brick.height * i

                bricks:insert(bricks, brick)

      end

end

Hi jerejigga,

It does not work…

In even rows bricks are stacked…

I will play around with this more  :slight_smile:

Tnx.

Hi jerejigga,

When you play around with x-es in even and odd rows everything turns out OK!

Many thanks!

That’s great! I am glad it worked it worked out for you!