Sorry for what took me a while.
Here is the piece of code that I would like to improve:
local physics = require(“physics”)
physics.start();
physics.setGravity(0,0);
physics.setDrawMode(“debug”);
local barierL
local barierR
local leaner
local leanHere = display.newGroup()
local function Move ( event )
leaner:setLinearVelocity(event.xRaw * 100000, 0)
end
barierL = display.newRect(leanHere, display.screenOriginX-75, display.contentHeight - 150, 40, 1000)
barierL.alpha = 0.0
physics.addBody(barierL, “static”, {bounce = 0, filter = { categoryBits = 2, maskBits = 4 }})
barierL.myName = “barierL”
barierR = display.newRect(leanHere, display.contentWidth-(display.screenOriginX)+75, display.contentHeight - 150, 40, 1000)
barierR.alpha = 0.0
physics.addBody(barierR, “static”, {bounce = 0, filter = { categoryBits = 2, maskBits = 4 }})
barierR.myName = “barierR”
leaner = display.newRect(leanHere, 384, 874, 200, 340)
leaner.alpha = 0.0
physics.addBody(leaner, {density = 0.5, bounce = 0, filter = {categoryBits = 4, maskBits = 2}})
leaner.isSleepingAllowed = false
leaner.myName = “leaner”
Runtime:addEventListener(“accelerometer”, Move)
The barierL and the barierR are stopping the leaner from going beyond the stage as it goes through the accelerometer function. My question through this entire discussion is how can I Limit the leaner’s location without the barierL and barierR? Thank you very much.