Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
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

  • 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 2019
    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

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +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 2019
    multitouch class - I gave you the above link


    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • olegoleg Member
    Also in gideros there is an example
    "event.touch.id"


    image.png
    1178 x 556 - 86K
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • EtereEtere Member
    Awesome. Thank you all for the help. I'm gonna check that out shortly oleg.
Sign In or Register to comment.