I can 't get the ball to bounce off my paddle below is my code.
I hope I can get some help on this
–
– main.lua
–
– Your code here
local physics = require(“physics”)
physics.start()
– Create a rectangle player one
myRect = display.newRect( 0, 0, 50, 100 )
–local myRect=display.newImage (“paddle1.png”)
myRect.x =100
myRect.y =125
– Add a body to the rectangle
—physics.addBody( myRect, “dynamic” )
–removed dynamic cause the paddle would move on its own. static was better
—physics.addBody( myRect, “static” )
physics.addBody( myRect, “static” ,{density = 1.0, friction = .3, bounce = .2})
– Set the linear velocity
—myRect:setLinearVelocity( 100, 20 )
---------------move paddle player#1
local function ontouch (event)
if event.phase == “ended” then
----moves it any where i click–
— transition.to (myRect,{x=event.x, y=event.y})
—just moves it up and down
transition.to (myRect,{y=event.y})
end
end
Runtime:addEventListener(“touch”, ontouch)
----draw ball
local myCircle = display.newCircle( 200, 200, 30 )
myCircle:setFillColor( 0.5 )
myCircle.x =300
myCircle.y =125
physics.addBody(myCircle,“dynamic”,{density=0.1,bounce = 0.4, friction = 1})
–physics.addBody(myCircle,“static”,{density=0.1,bounce = 4, friction = 1})
–myCircle:setLinearVelocity(-100,20)
----temp commented out
–myCircle:setLinearVelocity(math.random(-300,300),20)
--transition.to (myCircle,{x=myCircle.x-300, y=myCircle.y})
–transition.to (myCircle,{x=myCircle.x-math.random(-300,300), myCircle.y+math.random(-300,300)})
transition.to (myCircle,{x=myCircle.x-300, y=myCircle.y})
—collsion when ball hits paddle
local function ballcollison( self, event)
if ( event.phase == “began” ) then
print (“event began”)
elseif ( event.phase == “ended” ) then
print (“ball hit paddle”)
--myCircle.y =125
end
end
myRect.collision = ballcollison
myRect:addEventListener(“collision”)
myCircle.collision = ballcollison
myCircle:addEventListener( “collision” )