Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
One EventListener for multiple events - Gideros Forum

One EventListener for multiple events

Hello,

The past few weeks I've been learning about Gideros and Lua. I've been trying to figure out how to use one addEventListener for multiple events. I came across something called bubbling in JS, but haven't found a way to do it with lua. Is what I'm trying to do even possible with just lua?

Tagged:

Comments

  • olegoleg Member

    Likes: MoKaLux

    I do not understand English
    I am writing with the help of a google translator

    my blog: https://simartinfo.blogspot.com
    my games:
    https://play.google.com/store/apps/developer?id=AndroidMobileGame+(indie)
    Слава Україні
    +1 -1 (+1 / -0 ) Share on Facebook
  • Etere said:

    how to use one addEventListener for multiple events

    Hi!
    I don't get what exactly do you mean, syntax sugar for these declarations?
    	self:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin, self)
    	self:addEventListener(Event.TOUCHES_MOVE, self.onTouchesMove, self)
    	self:addEventListener(Event.TOUCHES_END, self.onTouchesEnd, self)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • SinisterSoftSinisterSoft Maintainer
    edited April 20
    Or do you mean one event function for different types of events - like this:
    function mouse(e)
      if e.type=="mouseDown" then
    -- here just mouse down
      elseif e.type=="mouseUp" then
    -- here mouse up
      else
    -- here everything else
      end
     
      -- this bit will be executed by mouseDown, mouseUp, mouseMove etc
    end
     
    stage:addEventListener(Event.MOUSE_HOVER,mouse)
    stage:addEventListener(Event.MOUSE_DOWN,mouse)
    stage:addEventListener(Event.MOUSE_UP,mouse)
    stage:addEventListener(Event.MOUSE_MOVE,mouse)
    stage:addEventListener(Event.MOUSE_WHEEL,mouse)
    I don't know if there is a function to add all events for a particular object to a single function in one call, might be useful though.. eg
    function stageEvents(e)
      -- here will get all events for the stage object
    end
    stage:addEventsListener(stageEvents)

    Likes: Apollo14, antix

    +1 -1 (+2 / -0 ) Share on Facebook
  • EtereEtere Member
    I may have worded it wrong. I'll try to explain what I'm trying to do.

    Okay so each block will be clickable.
    ■ ■ ■
    ■ ■ ■
    ■ ■ ■

    My goal is to click on a box then click on the adjacent box and have it draw a line. What I don't want is to have a bunch of EventListeners for every box.
  • olegoleg Member
    edited April 20
    multitouch class - I gave you the above link


    I do not understand English
    I am writing with the help of a google translator

    my blog: https://simartinfo.blogspot.com
    my games:
    https://play.google.com/store/apps/developer?id=AndroidMobileGame+(indie)
    Слава Україні
  • olegoleg Member
    Also in gideros there is an example
    "event.touch.id"


    image.png
    1178 x 556 - 86K
    I do not understand English
    I am writing with the help of a google translator

    my blog: https://simartinfo.blogspot.com
    my games:
    https://play.google.com/store/apps/developer?id=AndroidMobileGame+(indie)
    Слава Україні
  • EtereEtere Member
    Awesome. Thank you all for the help. I'm gonna check that out shortly oleg.
Sign In or Register to comment.