Jump to content

Tween on Click stops after rapid clicks


CyborgNachte
 Share

Recommended Posts

Hey there! I'm pretty new to Phaser, but I've been making an idle clicker in it to learn the ropes.

I've run into some issues with tweens that I'm not to sure how to fix. I have a sprite, and when you click it, it increments a counter and plays a 'bouncy' tween, to display you clicked on it.

This is cookie clicker style, so the user will inevitably rapid fire click it at some point. The issue seems to be that after several rapid fire clicks, the tween just sort of gives up and stops working.

My first assumption is that because we're creating a tween each time we get some kind of overload of them because we're not properly destroying them? I'm unsure how to effectively do this in this situation.

The ways I attempted to fix it:

  • use game.tween.remove(tweenName) at the end of the function (expecting the next click to create a new one)
  • store tween in variable and if variable != null, clear variable before creating new tween in it.

Neither of these had results which makes me think I'm not understanding this correctly.

Code:

crystal = game.add.sprite(game.world.centerX, game.world.centerY - 5, 'crystal');
	crystal.anchor.set(0.5);
	crystal.inputEnabled = true;
	crystal.input.pixelPerfectOver = true;
	crystal.input.useHandCursor = true;
//on click event firing
	crystal.events.onInputDown.add(actionOnclick, this);

//this tween is just it moving up and down to 'float'
	game.add.tween(crystal.position).to( {y: game.world.centerY + 5}, 2200, Phaser.Easing.Linear.InOut, true, 500, 20, true).loop(true);

//on click event function
function actionOnclick(){
	
	
	game.add.tween(crystal.scale).to({x: 0.95, y: 0.95}, 300, Phaser.Easing.Bounce.None, true, 300, 0, true);
	
	counter++;
	text.setText('Glamour: ' + counter);
	
}

Note: the tween doesn't need to complete if the user clicks again, just start over. It does this, but after so many rapid clicks it stops doing anything.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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