Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

killTweensOf(target) does not stop target tweens, if called immediately after tween creation. #6173

Closed
michalfialadev opened this issue Jul 17, 2022 · 1 comment

Comments

@michalfialadev
Copy link

michalfialadev commented Jul 17, 2022

(sorry im not getting the list to fill out, ill just fill in the issue as best as i can)

[OS]
Win10

[Phaser version]
3.60.0-beta.9

[Trivia]
calling killTweensOf(target) on a target on which tween has been recently created (set to paused:false [or default eg 'not set']) does not stop said tween and rather the 'tween runs anyways'.

[Code to repro]
go to labs example:
https://labs.phaser.io/edit.html?src=src/tweens/immediate%20stop%20a%20tween.js&v=3.55.2

Copy paste following code and replace create() function in labs example:

function create ()
{
    var marker = this.add.image(100, 300, 'block').setAlpha(0.3);
    var image = this.add.image(100, 300, 'block');

    var tween = this.tweens.add({
        targets: image,
        x: 700,
        delay: 1000,
        duration: 6000,
        ease: 'Power2'
    });

    // doesnt stop tween
    this.tweens.killTweensOf(image);

    this.input.on('pointerdown', ()=>{
        // does stop tween
        this.tweens.killTweensOf(image);
    });
}

I can also confirm, that keeping an instance of created tween and calling myTween.stop() does stop the tween properly, but in my use-case keeping an instance is not preferable.

[Suggestion]
Reading the docs, on the surface it seems the tween should be stopped (bug herein reported), but also flagged to be removed from TweenManager, but the removal happens 'start of next frame'. I wonder if this could interfere with trying to use the same tween in the same frame (possibly from elsewhere) right after the kill, or some other such edge cases (using the reference in the same frame for 'reasons' eg 'other code not knowing that the kill happened and the reference shouldnt be used until next frame' or other). I wonder, would having a 'removeImmediately' flag to remove the tween from TM instantly (synchronously) help to alleviate such edge cases (whilst incurring perf overhead-which might be preferable)? Just worrying a bit about delayed cleanup whils some code that executes in current frame might want to use/create new of same instance, which is not fully collected (maybe i'm overthinking it).

[Possibly related]
(1) Issue: #6169
(2) might also affect myScene.tweens.addCounter (UNTESTED) and should be solved-for there as well.

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants