physical interaction between two images

I am designing a football game,since the ball should bounce back when it collides with the boundary of the field i tried to implement the same using a boundary image and a ball image and gave both the physical properties but they are not interacting the ball goes to a direction without colliding with the boundary

here is my code 

local physics = require(“physics”)

physics.start()

local boundary = display.newImage(“boundary.png”,display.contentWidth/2,display.contentHeight/2)

physics.addBody(boundary,“static”,{friction = 0,bounce=1})

local ball = display.newImage(“ball.png”,display.contentWidth/2,display.contentHeight/2)

physics.addBody(ball,“dynamic”,{friction = 0 ,bounce = 1 })

i tried to implement the same but by creating walls and the interaction was perfect 

_W = display.contentWidth

_H = display.contentHeight

local physics = require(“physics”)

physics.start(  )

physics.setGravity( 0, 0 )

local circle = display.newCircle(display.contentWidth/2,display.contentHeight/2,30)

physics.addBody(circle,“dynamic”,{friction = 0 , bounce = 1})

circle.linearDamping  = 7

local wallthickness = 10

local leftwall = display.newRect( 5, 0, wallthickness,960 )

physics.addBody(leftwall,“static”,{friction = 0, bounce = 1})

– top wall

local topwall = display.newRect( 0, 0, 640, wallthickness )

physics.addBody(topwall,“static”,{friction = 0 , bounce = 1})

– right wall

local rightwall = display.newRect(_W-wallthickness,0,wallthickness,960)

physics.addBody(rightwall,“static”,{friction = 0,bounce = 1})

–bottom wall

local bottomwall =display.newRect(0,_H+wallthickness-30,660, wallthickness )

physics.addBody(bottomwall,“static”,{friction=0,bounce = 1})

–left

local player1 = display.newCircle( 20 , _H/2 , 30 )

physics.addBody(player1,“dynamic”,{density = 1,friction = 0 , bounce = 1})

player1:setFillColor(0,0,1)

player1:setLinearVelocity(60,0)

   

Hey,

the problem is, that you create only one solid physic body and the ball is inside that body.

You would either need the boundaries to consist out of 4 offset rectangular physic bodys for the 4 walls, or you could use a chain body (which is simpler but has some cons).

All you need can be found in the Corona Docs for physics.addBody.

https://docs.coronalabs.com/api/library/physics/addBody.html

As a hint, search for “Offset/Angled Rectangular Body”, “Edge Shape (Chain) Body” and “Multi-Element Body” on that page.

Hey,

the problem is, that you create only one solid physic body and the ball is inside that body.

You would either need the boundaries to consist out of 4 offset rectangular physic bodys for the 4 walls, or you could use a chain body (which is simpler but has some cons).

All you need can be found in the Corona Docs for physics.addBody.

https://docs.coronalabs.com/api/library/physics/addBody.html

As a hint, search for “Offset/Angled Rectangular Body”, “Edge Shape (Chain) Body” and “Multi-Element Body” on that page.