There is no specific line of code to create an invisible wall.
In multiple lines you can:
- Make a rectangle,
- add a static body to the rectangle,
- move it to the edge of the screen,
- set the visible flag
- done… repeat three more times with slightly different code.
Here is some code (33 lines and not exact since the walls are just ‘on-screen’ so you can see them.
local w = display.contentWidth local h = display.contentHeight local centerX = display.contentCenterX local centerY = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentHeight local unusedWidth = fullw - w local unusedHeight = fullh - h local left = 0 - unusedWidth/2 local top = 0 - unusedHeight/2 local right = w + unusedWidth/2 local bottom = h + unusedHeight/2 require "physics" physics.start() --physics.setDrawMode( "hybrid" ) local leftWall = display.newRect( left + 10, centerY, 20, fullh ) leftWall:setFillColor(1,0,0) physics.addBody( leftWall, "static" ) local rightWall = display.newRect( right - 10, centerY, 20, fullh ) rightWall:setFillColor(0,1,0) physics.addBody( rightWall, "static" ) local topWall = display.newRect( centerX, top+10, fullw, 20 ) topWall:setFillColor(0,0,1) physics.addBody( topWall, "static" ) local bottomWall = display.newRect( centerX, bottom-10, fullw, 20 ) bottomWall:setFillColor(1,1,0) physics.addBody( bottomWall, "static" )
As you can see, this is not a quick thing to answer, and I guarantee you’ll need to make even more changes to this code to make it work for you. Having no context into your situation, it is hard to give a complete answer.
Note: I suggest folks ask questions with this thought in mind, “Spend more time asking your question than the person helping you will spend answering the question and you are doing the right thing.”
I just spent 30 minutes answering this question which at the rate I charge means I spent ~$38 of my time answering. I’m not asking for money here, I just want you to realize for many of us, time is really money.
We (staff like Perry & Rob as well as community members like myself) really want to help and want you to be successful here. The thing is, general questions are hard to answer with an exact answer.
Often it is better for us to point you in a direction where you can examine samples and docs.
Like the old saying says, “Give a man a fish and he eats for a day. Teach a man to fish and he eats for a lifetime.”
Finally, one of the best sources for sample code (besides the ones already presented) is the API docs page: