Chapter 4: Let's build an app

By now, you should have a good idea about some of the key techniques in Android, so in this chapter we work through putting together a simple game from scratch - but remember the same techniques of planning, design, deciding how to store information, and get input from the user, will be the same whatever sort of app you're creating.

  • 96 Let's build a game
    Whatever sort of app you want to build, you can follow our example to see how it's done
  • 100 Graphics and animation
    Learn how to use graphics and animation in Android apps
  • 104 STEP BY STEP Add animation with the Gameview library
    For 2D games, it's easy to make things go smoothly with the Gameview library
  • 106 Interaction
    Planning how users will work with your app is vital. We set out what you need to know
  • 110 The game code
    Discover how to start turning your ideas into real code
  • 116 High scores: Storing data
    Keeping records is essential to any app. We explain the different options
  • 120 Pause and resume
    Get to grips with what happens when your app stops and starts
  • 122 Finishing off the game
    Discover the finishing touches that will make your app seem polished
  • 124 STEP BY STEP: Sharing scores
    Learn how your app can make it easy to share information on social media

Pages 96-99

The simple code for this part of the magazine, which includes the start of our letters class, together with the logic for filling the playing board, using coloured labels, can be downloaded as Game Test 1, from the links on the left.

Please note that though this code works fine, I have found that some accessibility options on Android can cause it to crash. In particular, when using LastPass via the Android accessibility settings, the example may quit unexpectedly. Turn off LastPass and it will run just fine.

Page 102: Animation

The code to make text bounce is included in the Temperature Converter download at the left, but commented out.

Pages 106-115

This section of the magbook shows how to change from using labels to a proper game engine, in the shape of GameView. The code in Game Test 2 includes all the changes made up to page 115, which includes the addition of a custom dialogue class called yesNo, and the changes to our letters class to detect matching pieces to either side or up and down.

The code works, however please pay attention to the comments - we are not able to include the font files with the downloadable code from this site, so you will need to download some fonts and add them to your project, and ensure you change the names of the fonts (the .ttf files) in the code to match.

As ever, remember that if you are using fonts in a project, you should check to make sure you have the necessary permission, and pay the appropriate fees, where required.

Page 117: State Manager

This simple exampel show how you can use StateManager to retrieve a setting. You need to add the StateManager code module to your project, and also the Random Access File and Reflection libraries.

Dim termsagreed As Boolean
If StateManager.GetSetting2("termsagreed","false") = "true" then
     termsagreed = True
     termsagreed = False
End if

Pages 118-119: SQLite databases

The code for working with the SQLite databases can be found in the full version of the Type Attack code, downloadable from the link on the left, in the highscores activity.

Page 121: Errata

The printed text says "the timer triggers in moves_Click" and should instead read "the timer triggers in moves_Tick"

Page 122: Custom dialogs

The custom dialogs are in the yesNo class, included in the full Type Attack code download. Remember they will need appropriate fonts added to your project.

Page 124: Sharing information with intents

The code for this is included in the full Type Attack download. The screen shot code is in the main activity, while the sharing code is all in the highscores activity, and it can also be found on this page.

NOTE: None of the code downloads includes font files, so they will not run until you choose appropriate fonts and add them to the Files tab of your project. Remember to obtain permission for any fonts that require it. A list of the fonts used is on the Credits page.