Why is sprite.tintBottomLeft returning the wrong color in phaser 3?

Hello,
I’m currently working on a project using Phaser 3. I’m tring to save a sprite (“object” in the code section below) current color before modifying it. I am saving the values of tintBottomLeft, tintBottomRight, tintTopLeft and tintTopRigh into 4 other variables.

    object.on('pointerover', function() {

        console.log(object);
        console.log("_tintBL", object._tintBL);

        previousTintBL = object.tintBottomLeft;
        previousTintBR = object.tintBottomRight;
        previousTintTL = object.tintTopLeft;
        previousTintTR = object.tintTopRight;

        object.setTint(0xff00ff);
    });

    object.on('pointerout', function() {
        object.clearTint();

        object.setTint(previousTintTL, previousTintTR, previousTintBL, previousTintBR);

        previousTintBL = object.tintBottomLeft;
        previousTintBR = object.tintBottomRight;
        previousTintTL = object.tintTopLeft;
        previousTintTR = object.tintTopRight;
    });

The problem is that the sprite current color is 16711680. But when I’m accessing the variable _tintBL alone, the color is now 255 and I really don’t understand why this is happening (printed using console.log, image linked)

Any help ?

Because before version 3.50 tint used to be stored in BGR instead of RGB. https://github.com/photonstorm/phaser/blob/v3.24.1/src/gameobjects/components/Tint.js#L14

Given that it was applied automatically in the setter, but not reversed in the getter, the value reads as different one than what was set.

Either convert to RGB yourself, or update to the 3.50 beta version where it’s no longer an issue.

2 Likes

Alright thank you very much !
Now I understand