3秒后淡出文字

时间:2016-05-13 10:52:28

标签: javascript phaser-framework

我需要在3秒后对某些文本应用淡出效果。以下链接包含一个示例:

http://www.html5gamedevs.com/topic/8639-fade-out-text-after-2-second-delay/

但它没有用。

文本所在的函数:

buyitems_lettuce: function()
{
    if(this.pet.customParams.coin >= 60)
    {
        this.pet.customParams.coin -= 60;
        this.refreshStats();
    }
    else
    {
        var buyitemsText = {font: "bold 16pt Arial", fill: "#fff"};
            buyitemsText.stroke = "#A4CED9";
            buyitemsText.strokeThickness = 5;

        this.PriceLettuceBuyItems = this.game.add.text(70,100, "No coin for buy Lettuce", buyitemsText);

    }

},

1 个答案:

答案 0 :(得分:1)

buyitems_lettuce: function () {
    if (this.pet.customParams.coin >= 60) {
        this.pet.customParams.coin -= 60;
        this.refreshStats();
    }
    else {
        var buyitemsText = {font: "bold 16pt Arial", fill: "#fff"};
        buyitemsText.stroke = "#A4CED9";
        buyitemsText.strokeThickness = 5;

        this.PriceLettuceBuyItems = this.game.add.text(70, 100, "No coin for buy Lettuce", buyitemsText);

        this.game.add.tween(this.PriceLettuceBuyItems)
                .to({alpha: 0}, 1000, Phaser.Easing.Default, true, 3000)
                .onComplete.add(function () {
                        console.log("This is called when the tween is done.");
                    }, this
                );
    }
}

这应该这样做。