Skip to content

dispatchTweenEvent overwrites one of the callback's parameters #5753

@andrei-pmbcn

Description

@andrei-pmbcn

Where it says callback.params[1] = this.targets; in Phaser.Tweens.Tween#dispatchTweenEvent, the code overwrites your second parameter before calling the callback, which is clearly not something you want or are even warned about. This should be fixed, perhaps by appending this.targets to the start of callback.params instead of overwriting the second param. Calllbacks like these are created when calling myTween.setCallback().

/**
     * Internal method that will emit a Tween based Event and invoke the given callback.
     *
     * @method Phaser.Tweens.Tween#dispatchTweenEvent
     * @since 3.19.0
     *
     * @param {Phaser.Types.Tweens.Event} event - The Event to be dispatched.
     * @param {function} callback - The callback to be invoked. Can be `null` or `undefined` to skip invocation.
     */
dispatchTweenEvent: function (event, callback)
    {
        if (!this.isSeeking)
        {
            this.emit(event, this, this.targets);

            if (callback)
            {
                callback.params[1] = this.targets;

                callback.func.apply(callback.scope, callback.params);
            }
        }
    },

Also, in https://newdocs.phaser.io/docs/3.55.2/Phaser.Tweens.Tween#setCallback it says the params arrray is optional. The above code renders this documentation false, as an error is raised when the params argument is not included, because callback.params[1] returns undefined. Providing an empty params array fixes the error.

If you need more information, such as repro steps and a jsfiddle, I'll be happy to provide these.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions