O'Reilly logo

PhoneGap By Example by Andrey Kovalenko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Releasing a bubble

When the mouse or tap is released with a bubble selected, we need to follow these steps:

  1. Check for matches
  2. Remove matched bubbles
  3. Drop down bubbles above the removed bubbles
  4. Refill the board

We perform all these steps in the releaseBubble function:

function releaseBubble(selectedBubble, pointer) {
    checkAndKillBubbleMatches(selectedBubble);
    removeKilledBubbles();
    var dropBubbleDuration = dropBubbles();
    game.time.events.add(dropBubbleDuration * 100, refillBoard);
    window.allowInput = false;
    window.selectedBubble = null;
    window.tempShiftedBubble = null;
}

Here, you can see that we refilled the board with some timeout. We did it using the game.time.events.add function. The first parameter is timed out for calling the second parameter, that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required