I create a standard rectangle object. I add a listener to that object. The listener runs a function. The function get the number of taps, the x and y coordinates, and the event name (“tap”). I can’t figure out how to get which object was tapped.
I would like to figure out which object was tapped so that I can change the physics properties on that object (or the stroke width, color, whatever).
Here is some trimmed down code:
[blockcode]
–Text field to test values from tap event
local testTapEvent = display.newText(“Initial value”, 0, 0, native.systemFont, 32)
testTapEvent:setTextColor(255, 255, 255)
–Function that runs when the object is tapped.
local function testTap(event)
–I am able to get the event name, numtaps, etc without issue.
testTapEvent.text=event.name
–What I would like to do (actually, I want to change the physics applied to the body to static, but think I can get that once I can get ahold of the object… but if you know that as well, please add.)
–getobjectthatwastapped.setFillColor(255,0,0)
end
–Creation of rectangle
local myRectangle = display.newRect(0, 0, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
myRectangle:addEventListener( “tap”, testTap )
[/blockcode]
Thanks for any help. [import]uid: 59514 topic_id: 10132 reply_id: 310132[/import]