I have some code to try and stop some objects leaving the screen. Currently I spawn a wall on the left hand side of the screen with bounce = 1 but gravityscale = 0.
local leftwall = display.newRect(0,246,10,480) leftwall:setFillColor(0.5) physics.addBody(leftwall, {bounce=1, filter = {maskBits = 4, categoryBits = 2}}) leftwall.gravityScale = 0
Elsewhere I have code that spawns some objects.
flying = display.newImage("flyingfly.png", 12, 12) splat = display.newImage("flysplat.png",12,12) flygroup = display.newGroup() flygroup:insert(flying, true) flygroup:insert(splat, true) splat.isVisible = false physics.addBody(flygroup, {bounce = 1, density = 1, filter = {maskBits = 2, categoryBits = 4}}) flygroup.gravityScale = 0 flygroup:translate( halfW + math.random( -100, 100 ), halfH + math.random( -100, 100 ) ) flygroup:addEventListener( "touch", buttonListener )