Hi,
I'm writing a button class.
the standard procedure seems to be
function Button:init()
self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
end
function Button:onMouseUp(e)
if self:hitTestPoint(e.x, e.y) then
--do something or dispatch a custom event
end
end |
Now, what I'd like to have is a function
Button:checkTouch()
I want to check if the button is touched on mouse_up, on mouse_over, on mouse_down and what not.
And I don't want to nest all of this in an event listener. I generally try to avoid them as much as possible (because they are too complicated to manage in most cases, or I'm simply too stupid to use them properly).
my checktouch would look like this, but afaik it's not done like this:
function Button:checkTouch()
if self:hitTestPoint(mouse.x, mouse.y) then
return true
else
return false
end
end |
Do I really have to create an EventListener just to get the mouse position?
Thanks,
Holo
Comments
In every programming logic there are listeners, hooks . (onMouseMove, OnMouserelease vs vs..)
So my answer : Yes, you need listener.
From other frameworks I know functions like mouse.getPosition(), for which you don't have to take 3 extra steps.
Whatever, I'll see if I can wrap my head around that...
http://www.html5gamedevs.com/topic/1681-get-mouse-position/
But my logic says it will work .
In other sdk's beleive me that listeners are also registered behind. I am sure that it is hard-coded into the framework itself. You can easilly do it in Gideros also. Just write the code in "init.lua" hence "init.lua" is fired always first by Gideros.
Likes: Holonist
And if framework provides such functionality, it means they are doing the same as your example internally.
And they do it even if you don't need coordinates currently, what a waste of resources