Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
stage events — Gideros Forum

stage events

GregBUGGregBUG Guru
edited January 2012 in General questions
hi guys...

when subclassing the Sprite class and registering Event.ENTER_FRAME

from the documentation:
"Event.ENTER_FRAME event is dispatched to all Sprite instances no matter these instances are on the scene tree or not."

is there a way to avoid this?
TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
www.tntengine.com

Comments

  • atilimatilim Maintainer
    Here is the solution :)
    MySprite = gideros.class(Sprite)
     
    function MySprite:init()
      self:addEventListener(Event.ADDED_TO_STAGE, self.onAddedToStage, self)
      self:addEventListener(Event.REMOVED_FROM_STAGE, self.onRemovedFromStage, self)
    end
     
    function MySprite:onAddedToStage()
      self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
     
    function MySprite:onRemovedFromStage()
      self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
     
    function MySprite:onEnterFrame()
    end
  • GregBUGGregBUG Guru
    edited January 2012
    oh... thanks...

    i'm cleanig the "raw" code of gidhelix and try to optimize more...
    but i need to better understand how Gideros manages events...
    and execution flow of lua sources... (and Lua oop) :P

    sorry form my continuos silly questions... :(

    but i'm new to Lua and Gideros ;)

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • GregBUGGregBUG Guru
    edited January 2012
    @atilim

    1^st thanks for your code. it work fine

    but with this code i need to remove the sprite to the stage to stop it's events
    in my situation i need to leave the sprites on the stage but i would stop all events...

    i need to declare and raise an "user" event right?
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    There isn't a direct way to stop/remove all events. You should remove each event you want by calling removeEventListener. Just leave the sprite on the stage, but call removeEventListener with the exact parameters of addEventListener.
Sign In or Register to comment.