Book Image

PhoneGap By Example

Book Image

PhoneGap By Example

Overview of this book

Table of Contents (17 chapters)
PhoneGap By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 function is to refill the board. We need to be sure that all the existing bubbles have dropped down. In the end of the function, you can see that we disabled input. We enable it only when the board has finished refilling...