You can do something like (I have not tested):
local physics = require("physics") physics.start() local SCREEN\_BOTTOM = display.viewableContentHeight - display.screenOriginY local SCREEN\_TOP = display.screenOriginY local SCREEN\_RIGHT = display.viewableContentWidth - display.screenOriginX local SCREEN\_LEFT = display.screenOriginX local SCREEN\_CENTER\_X = display.contentWidth \* 0.5 local WIDTH = display.actualContentWidth local HEIGHT = display.actualContentHeight local WALL\_SIZE = 50 local function createWall(params) local wall = display.newRect( params.group, params.x, params.y, params.w, params.h ) wall.isVisible = false physics.addBody(wall, "static") return wall end local function onWallCollision(self, event) if event.phase == "ended" then if event.other.type == "my\_object" then -- Here you can destroy your object and create another display.remove(event.other) end end end local function createWalls() local group = display.newGroup() local right = createWall({ group=group, w=WALL\_SIZE, h=HEIGHT, x = SCREEN\_RIGHT + WALL\_SIZE\*0.5, y = SCREEN\_TOP + HEIGHT\*0.5 }) right.collision = onWallCollision right:addEventListener("collision", right) local left = createWall({ group=group, w=WALL\_SIZE, h=HEIGHT, x=SCREEN\_LEFT - WALL\_SIZE\*0.5, y=SCREEN\_TOP + HEIGHT\*0.5 }) left.collision = onWallCollision left:addEventListener("collision", left) local top = createWall({ group=group, w=WIDTH, h=WALL\_SIZE, x=SCREEN\_CENTER\_X, y=SCREEN\_TOP - WALL\_SIZE\*0.5 }) top.collision = onWallCollision top:addEventListener("collision", top) local bottom = createWall({ group=group, w=WIDTH, h=WALL\_SIZE, x=SCREEN\_CENTER\_X, y=SCREEN\_BOTTOM + WALL\_SIZE\*0.5 }) bottom.collision = onWallCollision bottom:addEventListener("collision", bottom) end createWalls()