Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to completely remove sprite? [solved] — Gideros Forum

How to completely remove sprite? [solved]

GameOverGameOver Member
edited March 2014 in General questions
Hi everyone! I have here a question...

Sprite has a event handlers like this:
function mySpriteClass:init()
        self:addEventListener(Event.ADDED_TO_STAGE, self.onAddedToStage, self)
        self:addEventListener(Event.REMOVED_FROM_STAGE, self.onRemovedFromStage, self)
end
 
function mySpriteClass:onAddedToStage()
        self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
 
function mySpriteClass:onRemovedFromStage()
        print("check for removed")
        self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
 
function mySpriteClass:onEnterFrame()
        print("do somethimg")
end
After performing
stage:removeChild(mySprite)
sprite disappears form screen well and the text "check for removed" printed, but sprite still remains in memory. So the
mySpriteClass:onEnterFrame()
will continue to execute end "do somethimg" continues printing.


How to completely remove sprite from memory?

Comments

  • mySprite=nil ?
    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
  • GameOverGameOver Member
    edited March 2014
    It does not help!

    So I do check like this after performing stage:removeChild(mySprite)
    print (type (mySprite))
    I getting a "nil". But the code in the onEnterFrame handler will continue to execute!
  • how about mySprite:removeEventListener(Event.ENTER_FRAME,mySprite.onEnterFrame,mySprite)

    before you remove it?
    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
  • Looks like I understood what was happening.
    I developed mySpriteClass with ZeroBraneIDE in live coding mode.
    Even a full stop and restart Gideros Player did not solve the problem.
    But when I close ZeroBrane and restart again - everything ran as it should :-)
    Looks like a ZeroBrane bug, this whole hour blown my brain!

    Thanks for the help anyway!
  • john26john26 Maintainer
    I think this is a feature of Gideros, though. In Gideros, if a sprite is removed from stage and nilled out (ie awaiting garbage collection) it can still receive ENTER_FRAME events. I've never understood why this is the case as it seems to cause problems and I can't think of any obvious advantage...? The "problem" (if such it is) applies only to ENTER_FRAME events, not touch events etc.
  • SinisterSoftSinisterSoft Maintainer
    edited March 2014
    I never add an enter_frame to sprites myself so have never encountered this (luckily). :)

    Sounds like a bug.
    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
  • ar2rsawseenar2rsawseen Maintainer
    @john26 is right, but in this situation he explicitly removed the even listener, so it should have been removed and stopped running.

  • john26john26 Maintainer
    edited March 2014
    @SinisterSoft, I'm the same, I only have one ENTER_FRAME attached to the stage which does all the updating. But lots of people use an OOP approach where you have ENTER_FRAMEs attached to many sprites which may go on firing even after the sprite has been removed. The solution seems to be to add lots of removeEventListener calls which shouldn't really be necessary IMO...

    I'd love to know why it was done this way? Is there any advantage?
    +1 -1 (+2 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    Curious guys about this one, is it still the case today?

    Likes: PaulH

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.