I made my own tweening library (I know about GTween, but I made it a long ago).
It have been working so far, but in one particular place it started to misbehave...
I went to investigate, and found out it is buggy, quite buggy, the fact it has been working so far is just... magic (no better word O.o)
Right now when I create a tween, the function creates a tween table, add a enterframe event listener to a sprite (that is a argument of the tweening function) and points to that tween parameters table.
When the tween gets removed, I do the opposite:
tween.sprite:removeEventListener(Event.ENTER_FRAME, tweenUpdate, tween.sprite);
I think this is wrong, because it is not working, my issue that is presented is that after I delete a tween, it keeps working... in this particular case it is a alpha value, the tween was supposed to set the alpha from 1 to 0 over 5 seconds, then stop.
It works, except after those 5 seconds when I click the object again, it goes from 1 to 0 again, but really quickily (I guess that about 2 or 3 frames).
I am thinking the tween is not gone...
So, is my code to remove the event listener wrong? prints assure me the line with the removeEventListener ran, but the tween does not stop (as soon as I set the alpha to 1, it tweens to 0 again, without me telling it to again).
Comments
1) in your case, are you sure tweenUpdate is still in the scope and referring to the same function?
2) Is it possible you are adding events multiple times?
3) can you add print statement to tweenUpdate function to make sure it is really the one that is executing after removal?
tweenUpdate is created on the file scope, it is a local function...
but in both cases, tween.sprite is a parameter of the function where those lines are inside (and they are not inside the same function).
I wonder if tween.sprite is breaking it...
1. A one main enterFrame assigned, and never being removed.
2. Create a table, ( updateTable1 = {} )
3. Any object that want an enterframe event, would be inserted to the table
For example, updateTable1 => for player, updateTable2 => for enemy, and so on.
I usually also put camera function on the same enterframe.
I also did this for touch event, that way we can control which would take priority, and which would act as multi touch, and so on.
Likes: DungDajHjep