Share Your Code

Make outside edge walls module

Posted by mightE, Posted on October 28, 2011

This is hardly groundbreaking.
It is a faster and easier way to make outside edges.
I heard something about a corona update involving modules so this may be broken. meh.

save as "walls.lua"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module(..., package.seeall)
 
local W = _W --display.contentWidth
local H = _H --display.contentHeight
 
function make()
 
wallGroup = display.newGroup()
local background = display.newRect(0,0,W,H)
background:setFillColor(40,40,40)
        local wall = {}
        
        wall[1] = display.newRect(0,0,0,H)
        wall[2] = display.newRect(0,0,W,10)
        wall[3] = display.newRect(W,0,0,H)
        wall[4] = display.newRect(0,H,W,0)
        
        for i = 1, 4 do
                physics.addBody(wall[i], "static", {bounce = 0})
                wallGroup:insert(wall[i])
                wall[i].id = "wall"
        end
end

Called using

1
2
walls = require("walls")
walls.make()


Replies

Joe Kool
User offline. Last seen 22 weeks 3 days ago. Offline
Joined: 1 Jun 2011

Ha, no way! this is too cool! thanks Andrew!!!

Much appreciated,
J.K.

optionniko
User offline. Last seen 6 weeks 2 days ago. Offline
Joined: 19 Jul 2011

hey anddrewscott,

one question... If u load the module and u r using storyboard, how do u clean up when going on to next storyboard scene?

Just "wallGroup:removeSelf();" and everything cleans up?

Thank you.

Nick