I’ve been pulling my hair out for the last couple of hours over this, so hoping somebody might eb able to shed some light.
I’m spawning balls and attaching collision listeners, like so:
function onLocalCollision( self, event )
print("onLocalCollision()")
if ( event.phase == "began" ) then
print( self.myName .. ": collision began with " .. event.other.myName )
elseif ( event.phase == "ended" ) then
print( self.myName .. ": collision ended with " .. event.other.myName )
end
end
local function newBall( params )
local xPos = math.random(100,300)
local yPos = math.random(100,200)
local ball = display.newCircle(xPos, yPos, params.radius)
ball.xdir = params.xdir
ball.ydir = params.ydir
ball.xspeed = params.xspeed
ball.yspeed = params.yspeed
ball.radius = params.radius
physics.addBody(ball, "kinematic", {density = 1, bounce = 0.3, friction = 0.1, radius = params.radius})
ball.collision = onLocalCollision
ball:addEventListener("collision", ball)
return ball
end
for \_,item in ipairs( params ) do
local ball = newBall( item )
balls[#balls + 1] = ball
group:insert(ball)
end
The balls are being spawned fine with a physics body attached, however the onLocalCollision is never firing. No errors, just no call to the function.
Any help would be appreciated.
[import]uid: 33275 topic_id: 35314 reply_id: 335314[/import]