Jump to content

searching a way to cancel all the tweens except one ....


espace
 Share

Recommended Posts

hi,

Assuming i have several tweens for example :

var tween_a;

var tween_b;

var tween_c;

var tween_d

....

how to cancel for example all the tweens except the tween_c

is it possible in a single line code ?

 

Link to comment
Share on other sites

  • 1 month later...

thanks with my library and your advice it's done.

//utils.js
var wait = ()=> (callback, duration) {
	setTimeout(callback, duration);
}
//config.js
var p = {
        o: cloud, //object
        t: 1000, //time
        d: 5000, //delay
	a: 1, //alpha
        e: Phaser.Easing.Elastic.Out //Easing
        //r: 85, //rotation
        //sx :2, //scalex
        //sy :4, //scaley
        //dx :400, //displacementx
        //dy :200, //displacementy 
        //y: true //yoyo,
        //dyo :800, //delay yoyo
}
//utils.js
var _tr = (game, p) => { //transition,game,parameter
	this.game = game
	if (p.e === null) {
		p.e = Phaser.Easing.Linear.None
	}
	this.s = () => { // start tween
		if (p.a !== null) { // alpha
			this.tw = game.add.tween(p.o).to({ alpha: p.a }, p.t, p.e, true, p.d);
		}
		if (p.r !== null) { //rotation
			this.tw = game.add.tween(p.o).to({ angle: p.r }, p.t, p.e, true, p.d);
		}
		if (p.sx !== null) { //scale
			this.tw = game.add.tween(p.o.scale).to({ x: p.sx, y: p.sy }, p.t, p.e, true, p.d);
		}
		if (p.dx !== null) { //displacement
			this.tw = game.add.tween(p.o).to({ x: p.dx, y: p.dy }, p.t, p.e, true, p.d);
		}
	}
	this.c = (callback, time) => { //complete
		let time_adapted = p.d + p.t + time
		wait(callback, time_adapted)
	}

	this.y = () => { //yoyo
		if (p.y !== null) {
			this.tw(true, p.dyo)
		}
	}
        this.p=()=>{ //pause
        this.tw.pause()
        }
        this.r=()=>{ //resume
        this.tw.resume()
       }
       this.s=()=>{ //stop
        this.tw.stop()
       }
	this.s() //start the tween
}
//main.js
var tw={}
tw[0] = new _tr(game,p)
tw[1] = new _tr(game,p)
//stop all expect n°1
for (i = 0; i < tw.length; i++) {
  if(i != 1){
    tw[i].s()
  }    
} 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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