Hi All,
I have a small question about physics
My First code is below:
[lua]local physics = require( “physics” )
physics.start()
motiony=0
local ball = display.newCircle( 50, 50, 20 )
ball:setReferencePoint(display.TopCenterReferencePoint)
physics.addBody( ball, “dynamic”, { friction=0, bounce=0 } )
ball.x = 100; ball.y = 100;
local wall = display.newRect( 0, 0, 20, 65 )
wall:setReferencePoint(display.TopCenterReferencePoint)
wall.x = 100; wall.y = 200
physics.addBody( wall, “static”, { friction=0, bounce=0 } )[/lua]
This code working properly.
Ball is dropping and it is stopping on wall… This is good.
And my seconde code is below too
[lua]local physics = require( “physics” )
physics.start()
motiony=0
local ball = display.newCircle( 50, 50, 20 )
ball:setReferencePoint(display.TopCenterReferencePoint)
physics.addBody( ball, “static”, { friction=0, bounce=0 } )
ball.x = 100; ball.y = 100;
local wall = display.newRect( 0, 0, 20, 65 )
wall:setReferencePoint(display.TopCenterReferencePoint)
wall.x = 100; wall.y = 200
physics.addBody( wall, “static”, { friction=0, bounce=0 } )
local up =display.newRect( 0, 0, 65, 65 )
up.x= 200
up.y= 400
function up:touch()
motiony = 2
end
up:addEventListener(“touch”,up)
local function moveball()
ball.y=ball.y + motiony
end
local function stop (event)
if event.phase ==“ended” then
motiony = 0
end
end
Runtime:addEventListener(“enterFrame”, moveball)
Runtime:addEventListener(“touch”, stop )
[/lua]
What am i want?
i want my ball when it comes to wall stop. Yes i know, i am changing x position but there is a wall. My Ball should stop
is it possible or not?