It looks like you're new here. If you want to get involved, click one of these buttons!
self:hitTestPoint(event.x, event.y) -- For this: self:ButtonCircleHitTest(event.x, event.y) |
-- Assumes: -- ButtonCircle is child to a parent button -- Parent button anchorPoint = (.5, .5) function ButtonCircle:circleHitTest(eventX, eventY) -- Get these if we don't have them yet if not self.myParent or not self.myRadius then self.myParent = self:getParent() self.myRadius = self.myParent:getHeight() * .5 end local x, y = self.myParent:getPosition() -- Grab position from parent -- Is touch distance from center within radius of circle? if self.myRadius > math.sqrt((eventX - x)^2 + (eventY - y)^2) then return true end end |
Likes: ar2rsawseen
Comments
A slight modification: compare the radius squared to distance squared. That way you can avoid taking the square root which is expensive:
self.myRadius^2 > (eventX - x)^2 + (eventY - y)^2
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Ah yes, this good. Thanks for sharing.
Also, if your object is in moving parent, you can use :
local x, y = self:localToGlobal(0,0)
Just check if the point (event.x, event.y) collides with the circle.
Yep, just ran into a problem with moving parent. Thanks for the tip.
@jdbc
I'm going to give this a shot... the video of the native demo looks pretty good.