Jump to content

Preloading and caching tweens


Recommended Posts

I'm sorry if this has already been answered before, I didn't see a topic.


I'm making a match 3 game similar to the one in the phaser2 examples.  When a player matches 3 gems, I have them bounce off the board.  So for a 6x6 tile board I move/bounce each of the collected gems to one of 5 places on the screen.


However when I was running some diagnostics on this, I have 3 different tweens going at the same time (scale, x linear, and y Phaser.Easing.Sinusoidal ), and it takes up to a few tenths of a second to create all these tweens and then start them.  So it's somewhat slow.  I'm fairly sure that this is due to creating the tweens, since I don't have much else that's happening at the same time (nothing happening in update() functions, not even allowing user input).


I'm wondering if I can somehow create the tweens for all 36 tiles ahead of time (probably more efficient), and just use them later on so that no calculations need to be done.


If so- how?


Right now my current implementation:

GemObj.prototype.collect = function() {  var targetX = TOTALS_LOCATIONS[this.frame][0];  var tweenX = game.add.tween(this);  tweenX.to({x: targetX}, jumpDuration + collectDuration + pauseDuration, Phaser.Easing.Default);  var tweenY = game.add.tween(this).to({}, pauseDuration, Phaser.Easing.Default)                       .to({y: this.y - jumpHeight}, jumpDuration, Phaser.Easing.Sinusoidal.Out)                       .to({y: TOTALS_LOCATIONS[this.frame][1]}, collectDuration, Phaser.Easing.Sinusoidal.Out);  var tweenScale = game.add.tween(this.scale).to({}, pauseDuration + jumpDuration, Phaser.Easing.Default)                             .to({y: .3, x : .3}, collectDuration, Phaser.Easing.Default);  tweenX.onComplete.add( this.recycleGem, this);  tweenY.onComplete.add( this.recycleGem, this);  tweenScale.onComplete.add( this.recycleGem, this);  tweenX.start()  tweenY.start();  tweenScale.start();  activeTweens.push(tweenX);  activeTweens.push(tweenY);  activeTweens.push(tweenScale);};
Link to comment
Share on other sites


  • Recently Browsing   0 members

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