create a container which objects can go into

Hi everyone, I was wondering if anyone knew if there was a way to make a container, lets say a wooden barrel for example, that an object like a ball can go into. I would want something to happen when the ball touched the bottom of the barrel. If I use an image of a barrel, the ball will trigger the listener as soon as it touches the top rim of the barrel.

I was thinking if there was a way to create an object with sides and a bottom and overlay an image of a barrel on it. This image would have to remain on top of any other image it comes into contact with and this could simulate the ball “going into” the barrel. Just a thought.

If anyone could provide any advice it would be most appreciated! Thanks! [import]uid: 31262 topic_id: 7364 reply_id: 307364[/import]

Create a group consisting of static or kinematic physics side walls and bottom wall just using thin rects so you now have a U shaped composite object. Last, add the barrel image to the group so it covers the physics objects. The unseen base wall could be your sensor for colliding with the ball. [import]uid: 3953 topic_id: 7364 reply_id: 26070[/import]

Thanks for your reply Mark.

I did a quick test and created the walls and floor and put them in a group however I have no idea how to add physics to the group. This is a snippet of what I have so far:

local container = display.newGroup()  
local leftWall = display.newRect( container, 25, 350, 5, 60 )  
local rightWall = display.newRect( container, 105, 350, 5, 60 )  
local bottomWall = display.newRect( container, 25, 405, 85, 5 )  
physics.addBody( container, "kinematic", { friction=0.7 } )  

Now this code also includes other items as I just added it to the drag platform sample code. I have tried changing the physics properties for the “container” group all resulting in either the group not interacting with any of the other objects or the container group spiraling around the screen in a comical fashion. Does anyone have any insight? Thanks again. [import]uid: 31262 topic_id: 7364 reply_id: 26152[/import]

I think I figured this out without using a group. This is what I have:

local leftWall = display.newRect( 25, 350, 5, 60 )  
local rightWall = display.newRect( 105, 350, 5, 60 )  
local bottomWall = display.newRect( 25, 405, 85, 5 )  
physics.addBody( leftWall, "kinematic", { friction=0.1 } )  
physics.addBody( rightWall, "kinematic", { friction=0.1 } )  
physics.addBody( bottomWall, "kinematic", { friction=0.1 } )  
  
local barrel = display.newImage( "barrel.png" )  
barrel.x = 75; barrel.y = 370  

The barrel.png sits overtop the 3 rectangles and covers them. The ball shows the illusion of going into the barrel. Can anyone tell me if this looks correct or if using kinematic may cause issues with any other aspects? I will want the bottomWall object to do a colission test eventually. Thanks. [import]uid: 31262 topic_id: 7364 reply_id: 26161[/import]