Jump to content

Change sprite animation during a tween at each endpoint


jojomanzo
 Share

Recommended Posts

I have been working with phaser for less than a week, working off of some sample code. 

I am able to load the sprite.

Have the sprite walk/tween 50 pixels back and forth with yoyo.

But I can't figure out how to get it to change animation from 'left' to 'right'.  You may recognize parts of the code in the sample below, I even left some other attempts commented out so that you can see I did search this site and Google my problem, but I can't find a solution.

 

Basically, I want to have the sprite constantly patrol, and the yoyo works fine. But after each tween, I need to switch the animation so the person faces left or right.  Any ideas will be helpful!

 

var spriteX = this.game.add.sprite(600, 1000, 'walking');
	
	var tween = this.add.tween(spriteX);
	
	spriteX.frame = 3;
	spriteX.animations.add('left', [9, 10, 11], 10, true);
	spriteX.animations.add('right', [3, 4, 5], 10, true);
	spriteX.animations.play('left');
	tween.to({ x: 650 }, 1000, Phaser.Easing.Linear.None, true, 1000, -1, true);
	tween.onComplete.add(doSomething, this);
	function doSomething () {
		spriteX.animations.stop('left');
		
		spriteX.animations.play('right');
	}
	tween.to({ x: 600 }, 1000, Phaser.Easing.Linear.None, true, 1000, -1, true);
	
	//spriteX.animations.play('left');
	//spriteX.animations.stop('left');
	tween.repeatDelay(1000); 
	tween.yoyoDelay(1000);
	//spriteX.animations.stop('right');


    
  

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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