Jump to content

Question about change texture in tween onReapeat


HugoMM
 Share

Recommended Posts

I modified the tween loop examples in v3.

I'd like to change the texture when every tween loop finished.

But the texture flickers after setTexture(). Am I doing anything wrong?

 

var config = {
    type: Phaser.WEBGL,
    width: 800,
    height: 600,
    backgroundColor: '#2d2d2d',
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('block', 'assets/sprites/block.png');
    this.load.image('arrow', 'assets/sprites/arrow.png');
}

var name = ['block', 'arrow'];
var i=0;

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

    this.tweens.add({
        targets: image,
        x: 300,
        duration: 1000,
        repeat: -1,
        onRepeat: function(tween, target){
            target.setTexture(name[++i%2]);
        }
    });
}
 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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