Hi Andrew,
The function wasn’t necessarily intended for use in an event listener, but you can just set it up like this, for example:
local function distanceBetween( point1, point2 )
local xfactor = point2.x-point1.x ; local yfactor = point2.y-point1.y
local distanceBetween = math.sqrt((xfactor\*xfactor) + (yfactor\*yfactor))
return distanceBetween
end
local function checkDistance( event )
local thisDistance = distanceBetween( [one object], [other object] )
print(thisDistance) --for testing only, remove this line later
end
Runtime:addEventListener( "enterframe", checkDistance )
So in essence, the Runtime listener is actually calling the function “checkDistance” which in turn calls (and receives in return) the distance from “distanceBetween”. This structure will also allow you to retrieve the distance between any number of objects in the same game cycle. You’d just need to call “distanceBetween” for each pair, all within the “checkDistance” function.
Does this help?
Brent
[import]uid: 9747 topic_id: 3709 reply_id: 53978[/import]
[import]uid: 82408 topic_id: 3709 reply_id: 56948[/import]