Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
The ENTER_FRAME event is not removed when removing the sprite? — Gideros Forum

The ENTER_FRAME event is not removed when removing the sprite?

Greetings guys, I have a problem that I believe is something I'm doing wrong. I'm using the downloadable game template (which has the effects of changing scenes).

When calling the game level, I add (addChild) the characters that are created with the Sprites class that has in them the event ENTER_FRAME (where it controls the animations, adds and deletes particles, movieclipes etc ...).

When I remove the Level scene the character's ENTER_FRAME keeps running endlessly, even if I remove (with removeChild) the event is still active ...

What is the correct procedure in these cases? Does anyone have any ideas?

Thanks.

Comments

  • olegoleg Member
    edited January 2020
    https://wiki.giderosmobile.com/index.php/EventDispatcher:removeEventListener
    EventDispatcher:removeEventListener(type,listener,data)
    https://wiki.giderosmobile.com/index.php/Event_system
    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(event)
    	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
    function MySprite:onRemovedFromStage(event)
    	self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
    function MySprite:onEnterFrame(event)
    	-- enter frame logic
    end

    Likes: kinrpg, plicatibu

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+2 / -0 )Share on Facebook
  • kinrpgkinrpg Member
    edited January 2020
    oleg said:

    https://wiki.giderosmobile.com/index.php/EventDispatcher:removeEventListener

    EventDispatcher:removeEventListener(type,listener,data)
    https://wiki.giderosmobile.com/index.php/Event_system
    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(event)
    	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
    function MySprite:onRemovedFromStage(event)
    	self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
    function MySprite:onEnterFrame(event)
    	-- enter frame logic
    end
    Thank you.
    I redid this piece of code in my project and it worked. Now I'm reviewing it and finding that a lot was running when it shouldn't be.

    :smiley:
  • kinrpg said:

    oleg said:

    https://wiki.giderosmobile.com/index.php/EventDispatcher:removeEventListener

    EventDispatcher:removeEventListener(type,listener,data)
    https://wiki.giderosmobile.com/index.php/Event_system
    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(event)
    	self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
    function MySprite:onRemovedFromStage(event)
    	self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
    end
    function MySprite:onEnterFrame(event)
    	-- enter frame logic
    end
    Thank you.
    I redid this piece of code in my project and it worked. Now I'm reviewing it and finding that a lot was running when it shouldn't be.
    You may not be deleting all events, try this:
    https://wiki.giderosmobile.com/index.php/EventDispatcher:removeAllListeners

    Likes: kinrpg, plicatibu

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+2 / -0 )Share on Facebook
  • @oleg
    I reconfigured the codes of the scenes and game objects following their suggestions. It worked very well. It is now clearing events and removing objects correctly right after the scene is changed.
    Thank you very much for your help.

    Likes: oleg, antix

    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.