Hello,
So, I’m just messing around with Lua to see if I can get a handle on things, and am trying to write a basic program. When you touch, new physics bodies are created. But I want to add a different touch event specific to each body, so that if they are touched, an impulse is applied to them. My functions are as follows:
local function touched(event)  
 if event.phase == "began" or event.phase == "moved" then  
 local dot = display.newCircle(event.x, event.y, 20, 20)  
 dot:setFillColor(math.random(80),math.random(110),math.random(250))  
 physics.addBody(dot, { bounce = 0.8, friction = 1.0})  
 end  
end  
and
local function touchDot(event)  
 local dot = event.target  
 dot:applyLinearImpulse( 0, -0.2, event.x, event.y )  
end  
Then, I have the runtime event to call the touched function:
Runtime:addEventListener("touch", touched)  
So, now, how can I add an event listener to each dot that is created, so if they are touched, the touchDot function is called?
Thanks!
Logan [import]uid: 44896 topic_id: 7808 reply_id: 307808[/import]
      
    
 [import]uid: 6981 topic_id: 7808 reply_id: 27702[/import]