Hello. I’m a beginner and i’m working on an assignment at school. I want to make a rectangle as the wall that fit the screen so the ball could bounce. i used display.newRect to create a rectangle but the sides are not connected to each other because of the wrong dimensions so there are holes on the sides where the ball would disappear if it touches those areas. How do i fix it? Thank you
The display is Iphone 5 640x1136
Here is my code:
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 4.9)
local background = display.newImage(“bkg_bricks.png”, 130, 240);
local balloon = display.newImage(“red_balloon.png”)
balloon.x = display.contentWidth/2
physics.addBody(balloon, { bounce = 1, radius = 45, friction = 0.9} )
local leftWall = display.newRect(0, 0 , 0, display.contentHeight )
local rightWall = display.newRect( display.contentWidth, 0, 0, display.contentHeight )
local ceiling = display.newRect(0, 0, display.contentWidth, 1 )
physics.addBody(leftWall, “static”, { bounce = 0.1} )
physics.addBody(rightWall, “static”, { bounce = 0.1} )
physics.addBody(ceiling, “static”, { bounce = 0.1} )
local floor = display.newImage(“floor.png”, 30, 10);
floor.y = display.contentHeight+25
physics.addBody(floor, “static”, { bounce = 0.0, friction = 1.0})
display.setStatusBar(display.HiddenStatusBar);
function moveBalloon(event)
local balloon = event.target
balloon:applyLinearImpulse( 0, -0.2, event.x, event.y )
end
balloon:addEventListener(“touch”, moveBalloon)