I’m trying to write button that will deal three cards face down (each separated by 100px). My current code works to stop dealing when three cards are dealt, until the reset button is clicked. The problem occurs if the user rapidly clicks dealButton before three cards are dealt. It will deal more cards than I need. Is there an easy way to make the button a one-shot from the moment it is clicked, until it is reset?
Also, how can I remove the cards that are dealt when I press the reset button?
Instead of .on you could use .once. Or, set a flag when the pointerdown function is called to track that the cards are dealing/dealt, and run/don’t run the function based on it.
And don’t use setTimeout; either use a phaser timer, or incorporate onComplete parameters into your tween.
You can repeat the same tween multiple times by setting repeat property and you can add onRepeat callback that will be called every time tween repeats. You can change value of x before tween repeats.
You can also use onStart callback to disable dealing btn and enable it in onComplete callback.
With the code above, when I click dealButton, three cards are dealt at x=300. After I reset the button and press it again it will deal three cards at x=400 and so on. I’ve also tried to use loop instead of repeat and it’s not exactly clear what is the difference between them.
How can I change x to x+=100 so that the cards are dealt 100px away from each other?