1- I subclass Sprite to my_awesome_sprite to add some properties and touch events.
2- I create a new sprite:
auto super_sprite = my_awesome_sprite::create();
Then I do some other stuff, and then I ended up not using the super_sprite (so no added as a child to node/layer etc…). Then the function ends and super_sprite is destroyed by the system (I added a log on the destructor and got confirmation)
So, the object has been destroyed right? Right. But not its touch events… The touch event still triggers even the object no longer exists and this causes a error and crash.
So my question is: do I have to destroy the touch events myself in the destructor? how can I do that?
Hi, yes I tried this code some time ago but does not compile… there are some errors.
Still my issue is not creating the touch events… the problem is they are not destroyed when the object is destroyed. Is that a normal behaviour? Do I have to take care of them myself? How can I do it? How can I destroy the events?
I guess if the object is properly attached to another cocos object and later removed this wont happen right? Maybe this happens only because I didnt add it as a child to a scene or another cocos node?
Someone mentions this: “if you add it with fixed priority, then you will need to remove the event listener manually.” Actually this is what I’m doing… I use “addEventListenerWithFixedPriority”
So thats why I have to remove the listener myself (I did it and it works fine now). Is this behaviour explained anywhere in the documentation?