How to make a falling block pass behind a wall?

I have a code like this:

[code]function new()
local w = display.contentWidth;
local h = display.contentHeight;

local physics = require(“physics”);
physics.start();

local localGroup = display.newGroup();
local block;
local wall;

local function blockCreator()
block = display.newRect(0, 0, w, 100);
block.x = math.random(0, w); block.y = math.random(-20, 0);
physics.addBody(block);
localGroup:insert(block);
end
timer.performWithDelay(1000, blockCreator, 2);

wall = display.newRect(0, 0, w, 100);
wall.x = w/2; wall.y = h/2;
localGroup:insert(wall);

return localGroup;
end
[/code]

I want the blocks created by the function blockCreator() to pass behind the wall. What am I supposed to do to make it happen? [import]uid: 162818 topic_id: 35685 reply_id: 335685[/import]

Normally when you create a display object and you add it to a group, the last thing added to the group is the item in front. The first thing added iss to the back.

Since you’re creating your blocks on a timer, your wall is actually getting created first and the blocks afterwards.

I would consider doing a:

wall:toFront()  

inside your block spawn after you add the block to the group. This would keep your wall in front.
[import]uid: 199310 topic_id: 35685 reply_id: 141916[/import]

It worked.
Thank you, Rob. :slight_smile: [import]uid: 162818 topic_id: 35685 reply_id: 142118[/import]

Normally when you create a display object and you add it to a group, the last thing added to the group is the item in front. The first thing added iss to the back.

Since you’re creating your blocks on a timer, your wall is actually getting created first and the blocks afterwards.

I would consider doing a:

wall:toFront()  

inside your block spawn after you add the block to the group. This would keep your wall in front.
[import]uid: 199310 topic_id: 35685 reply_id: 141916[/import]

It worked.
Thank you, Rob. :slight_smile: [import]uid: 162818 topic_id: 35685 reply_id: 142118[/import]