Jump to content

Why flashing black instead of red in this tween?


MichelF
 Share

Recommended Posts

 // Flash player red
 let tintTween = this.tweens.add({
     targets: this.player,
     duration: 200,
     tint: 0xff0000,
     callbackScope: this,
     onComplete: function(tween, sprites) {
         // Return to original color
         this.player.clearTint();
     }
 });

This code is making my player sprite flash black and go back to normal, why is it not flashing red?

Link to comment
Share on other sites

  • 1 year later...

You can't set the tint directly like this.

 What I do is

takeDamage() {
   flashColor(0xFF0000); 
}

flashColor(color) {
 
    this.setTint(color);

    this.scene.time.addEvent({
           delay: 200,
           callback: function(){ this.clearTint(); },
           callbackScope: this,
        });
}

 

Here's one example of how to achieve it: https://phaser.discourse.group/t/how-phaser-can-make-a-flashing-animation-of-sprite/1503/4

Here's a more advanced one: 

 

Link to comment
Share on other sites

  • 3 months later...

Is there a way to break a Phaser 3 project down into multiple files for objects (Player.js, Enemy,js) and scenes (Boot.js, Game.js...) while using ES6 classes but without Node.js, Webpack and so on? All the templates I found rely on some additional app and I'd like to avoid using them. Starting with Phaser 3 has been way more complicated than starting with Phaser 2 years ago. By Setting up all those dependencies and debugging them has been a huge time sink and they still don't work to my great frustration. In Phaser 2 it was a matter of linking all the files in the main HTML file via the <script src="..."></script> tag in the right order, and adding all the states to the global game object. I appreciate it wasn't ideal but it was simple.

Michael
best wow gaming keyboards

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...