Create a Bubble Popping Game - Adding Interaction


This Cyber Monday Envato Tuts+ courses will be reduced to just $3. Don't miss out.

This is the second installment in our Corona SDK Bubble Popping game tutorial. In today's tutorial, we'll add to our interface by coding the game interaction. Read on!

Also available in this series:

  1. Create a Bubble Popping Game - Interface Creation
  2. Create a Bubble Popping Game - Adding Interaction

Where We Left Off. . .

Please be sure to check part 1 of the series to fully understand and prepare for this tutorial.

Step 1: Start Button Listeners

This function adds the necesary listeners to the TitleView buttons.

Step 2: Show Credits

The credits screen is shown when the user taps the about button, a tap listener is added to the credits view to remove it.

Step 3: Hide Credits

When the credits screen is tapped, it'll be tweened out of the stage and removed.

Step 4: Show Game View

When the Start button is tapped, the title view is tweened and removed revealing the game view. There are many parts involved in this view so we'll split them in the next steps.

Step 5: Walls

Next we add the walls to the stage. They are created using the drawing API.

Step 6: Bubbles

This part creates five bubbles in the screen at a random position.

Step 7: Bubble Physics

Here we add physics to our new bubble.

Step 8: Wall Physics

And do the same with our walls.

Step 9: TextFields

Now we add the level, popped and required bubbles textfields.

Step 10: Game Listeners

This function adds the necessary listeners to start the game logic.

Step 11: Create Bullets

This code runs when the background is tapped.

First we create the bullet graphics.

Step 12: Set Direction

Then we give it a direction by setting the linear velocity.

Step 13: Collisions

The collisions are handled by the next function. A sound is played, the score increases and removes the bubble of the screen.

Step 14: Remove Offstage Bullets

This code will remove any bullet that is out of sight.

Step 15: Level Complete

Here we check if the popped bubbles have reached the required quantity and call a win alert if true.

Step 16: Alert

The alert function displays a message according to the type of alert called (level complete or failed).

Step 17: Call Main Function

In order to start the game, the Main function needs to be called. With the above code in place, we'll do that here:

Step 18: Loading Screen

The Default.png file is an image that will be displayed right when you start the application while the iOS loads the basic data to show the Main Screen. Add this image to your project source folder, it will be automatically added by the Corona compliler.

Step 19: Icon

Using the graphics you created before you can now create a nice and good looking icon. The icon size for the non-retina iPhone icon is 57x57px, but the retina version is 114x114px and the iTunes store requires a 512x512px version. I suggest creating the 512x512 version first and then scaling down for the other sizes.

It doesn't need to have the rounded corners or the transparent glare, iTunes and the iPhone will do that for you.

Step 20: Testing in Simulator

It's time to do the final test. Open the Corona Simulator, browse to your project folder, and then click open. If everything works as expected, you are ready for the final step!

Step 21: Build

In the Corona Simulator go to File > Build and select your target device. Fill the required data and click build. Wait a few seconds and your app will be ready for device testing and/or submission for distribution!


Experiment with the final result and try to make your custom version of the game!

I hope you liked this tutorial series and find it helpful. Thank you for reading!