Yanifska Posted May 6, 2015 Share Posted May 6, 2015 Hi there I have a character "patrol" with this tween. this.myTween = game.add.tween(this).to({ x: this.x + dist }, Phaser.Timer.SECOND*patrolSpeed, Phaser.Easing.Quadratic.InOut, true, Phaser.Timer.SECOND * game.rnd.integerInRange(0.5,2), 10000, true); I'd like to add a stop between each loop.how would you go for that ? Link to comment Share on other sites More sharing options...
Tom Atom Posted May 6, 2015 Share Posted May 6, 2015 Hi, look at these TweenData properties: repeatDelay and yoyoDelay. You can set it through Tween methods: repeatDelay() a yoyoDelay(). This is working example of "patroling" with 1 second delay: var sprite = this.add.sprite(100, 100, "Atlas", "Sprite", this.world); var tween = this.add.tween(sprite); tween.to({ x: 200 }, 1000, Phaser.Easing.Linear.None, true, 1000, -1, true); tween.repeatDelay(1000); tween.yoyoDelay(1000);1000 millis delay is in tween's to() and it is first delay before tween starts. repeatDelay and yoyoDelay are there for delay before each repeat as well as before each yoyo return. I also recommend to replace number of repeats (10000 in your code) with -1 (= forever)... drhayes and Yanifska 2 Link to comment Share on other sites More sharing options...
Yanifska Posted May 6, 2015 Author Share Posted May 6, 2015 thanks a lot I got an error message Uncaught TypeError: this.myTween.repeatDelay is not a function I am on phaser 2.2.2 btw and the code is located inside a prototype: function Enemy1(game, X, parent, dist, patrolSpeed){ Phaser.Sprite.call(this, game, X, yPos - 80, 'guard') //some stuffs this.myTween = game.add.tween(this).to({ x: this.x + dist }, Phaser.Timer.SECOND*patrolSpeed, Phaser.Easing.Quadratic.InOut, true, Phaser.Timer.SECOND * game.rnd.integerInRange(0, 1.5), -1, true); this.myTween.repeatDelay(4000); this.myTween.yoyoDelay(4000); this.myTween.onLoop.add(function(){ this.scale.x *= -1; }, this);}Enemy1.prototype = Object.create(Phaser.Sprite.prototype);Enemy1.prototype.constructor = Enemy1; Link to comment Share on other sites More sharing options...
Tom Atom Posted May 6, 2015 Share Posted May 6, 2015 There is change between 2.2.2 and 2.3.0 in 2.2.2 you should write:this.myTween.repeatDelay = 4000;and it looks like yoyoDelay is not there at all in 2.2.2 Link to comment Share on other sites More sharing options...
Recommended Posts