Hi fokes I’m new to Corona. So far I’m loving it. I’ve been stuck at for little while trying to solve this issue.
I have a object that i call a “ball”. It’s position is controlled by the accelerometer. Basically i can move the ball around the screen or off the screen into oblivion. So naturally I put up static walls to stop the ball from leaving the play field. However the ball ignores the physics of the static walls / bodies and passes trough them with little hesitation.
The strange thing is if i programmatically move the ball position to a wall it reacts to the static walls i’ve put up.
Any suggestions would be very helpful
Thank you in advance!
Here is the code that is the main control.
[code]
display.setStatusBar (display.HiddenStatusBar)
local physics = require (“physics”)
physics.start()
physics.setGravity(0,0)
physics.setDrawMode(“hybrid”)
local screenW, screenH = display.contentWidth, display.contentHeight
local leftWall = display.newRect(0,0,1,screenH)
local rightWall = display.newRect(screenW ,0,1,screenH)
local ceiling = display.newRect(0,0,screenW,1)
local floor = display.newRect(0,screenH,screenW,1)
physics.addBody (leftWall, “static”, {density=5, bounce=0.1, friction=0.5})
physics.addBody (rightWall, “static”, { density=5, bounce=0.1, friction=0.5})
physics.addBody (ceiling, “static”, { density=5, bounce=0.1, friction=0.5})
physics.addBody (floor, “static”, { density=5, bounce=0.1, friction=0.5})
background = display.newImage (“background.png”)
ball = display.newImage (“ball.png”)
ball.x = 160
ball.y = 200
physics.addBody(ball, “dynamic”, {density=5, friction = 1.0, bounce=0.6})
–> Adds the ball and adds physics to the ball
–< momemtarily respects the walls then falls threw them.
local motionx = 0
local motiony = 0
local function onAccelerate( event )
motionx = 35 * event.xGravity
motiony = 35 * event.yGravity
end
Runtime:addEventListener (“accelerometer”, onAccelerate)
local function moveball (event)
ball.x = ball.x + motionx
ball.y = ball.y - motiony
end
Runtime:addEventListener(“enterFrame”, moveball)
[/code] [import]uid: 2165 topic_id: 9825 reply_id: 309825[/import]
