1. Code
  2. Corona SDK

Build an Apple Catcher Game - Adding Interaction

Read Time:6 minsLanguages:

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

Also available in this series:

  1. Build an Apple Catcher Game - Interface Creation
  2. Build an Apple Catcher 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: Add Basket

This code places the basket on the stage.

Step 6: Info Bar

Next we add the Info Bar image and create the corresponding TextFields that will display the current score and time remaining.

Step 7: Add Physics

Now we add physics to the basket and call the function that will add the game listeners.

Step 8: Game Listeners

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

Step 9: Drag Basket

The following code uses the phase event property to drag the basket on the x-axis using the player's finger.

Step 10: Add Apple or Stick

The update function is executed every half second. Each time a random number is generated and then tested to see if an apple or a stick will be added to the stage. The item is then added to the physics engine and pulled down by gravity automatically.

Step 11: Decrease Timer

Here we increase the timer variable by one every half second so when it is equal to 2, a second is decreased from the timeLeft textfield.

Step 12: Check for Timer Completion

This part checks if the time available is over and calls an alert if so.

Step 13: Apple Collision

When an apple hits the basket it is removed from the stage, the score is updated, and an animation is showed displaying the amount of score raised.

Step 14: Stick Collision

This uses the same method as the last step, this time decreasing the score.

Step 15: Alert

This function will stop the game and display the final score using the alert background and tweening it.

Step 16: 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 17: 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 18: 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 19: 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 20: 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 own custom version of the game!

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

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.