I did this :
function scene:create(event) local screenGroup = self.view local randomImage = math.random(1,41) local background = display.newImageRect(screenGroup, "images/background"..randomImage..".jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY display.setDefault("fillColor", 0, 1, 1) CreateWalls(screenGroup,1) -- create image of a ball Ball = display.newCircle(100, 100, 10) physics.addBody(Ball, "dynamic", {friction=2}) Ball:applyLinearImpulse(-.05, .05, 0, 0) screenGroup:insert(Ball) end
and got this error :
bad argument #3 to 'newRect' (number expected, got table) stack traceback: in function 'newRect' C:\Users\user\Documents\Corona Projects\app\game.lua:51: in function 'CreateWalls' C:\Users\user\Documents\Corona Projects\app\game.lua:21: in function '?' This is the function with line 51 where the error is :
function CreateWalls(BorderWidth) -- make the math easier local OldAnchor = {x = display.getDefault(anchorX), y = display.getDefault(anchorY) } SetDefaultAnchor({x=0, y=0}) local Height = display.contentHeight -- + (2 \* BorderWidth) local Width = display.contentWidth -- + (2 \* BorderWidth) local leftWall = display.newRect(0, 0, BorderWidth, Height) -- this is where the error is local rightWall = display.newRect(Width - BorderWidth, 0, BorderWidth, Height) local ceiling = display.newRect(0, 0, Width, BorderWidth) local floor = display.newRect(0, Height-BorderWidth, Width, BorderWidth) physics.addBody (leftWall, "static", {bounce = 0.7, friction = 2}) physics.addBody (rightWall, "static", {bounce = 0.0, friction = 2}) physics.addBody (ceiling, "static", {bounce = 0.8, friction = 2}) physics.addBody (floor, "static", {bounce = 0.0, friction = 2}) -- restore previous defaults SetDefaultAnchor(OldAnchor) end