Hi all,
I am trying to make a class( Which is a display group ) have a local collision handler.
Here are some excerpts :
------------------------------------------------------- -- pickup.lua function pickup:touched() self.active = false end function pickup.new(x,y ) -- constructor local pickupGroup = display.newGroup() local items = {} pickupGroup.items = items pickupGroup.active = true local core = display.newCircle( x,y, 10 ) core:setFillColor(pickupColor[1],pickupColor[2],pickupColor[3],0.8) pickupGroup.core = core pickupGroup:insert(core) core.parent = pickupGroup table.insert( pickupGroup.items, core) return setmetatable( pickupGroup, pickup\_mt ) end
------------------------------------- -- gamescreen.lua local function onPickupCollision( event ) if ( event.phase == "began" ) then event.target.parent:touched() elseif ( event.phase == "ended" ) then end end local function addPickups(levelNumber,parent,globalYOffset) for i=1,#bank.levels[levelNumber].pickups do local x = bank.levels[levelNumber].pickups[i][1] local y = bank.levels[levelNumber].pickups[i][2]+globalYOffset local newPickup = Pickup.new(x,y) physics.addBody( newPickup.core , "static",{isSensor=true}) parent:insert(newPickup) newPickup.core.collision = onPickupCollision newPickup.core:addEventListener( "collision", onPickupCollision ) end end
So the pickup class actually contains several display objects, where i want to detect collisions with one of those objects ‘core’.
I want a function of that class to handle that collision.
The code above gives a nil error when executing this line
event.target.parent:touched()
Or is there a better way to do this ?
Thanks in advance,