Deploying the game so far

Before we explore any of the code and learn our first bit of Java, you might be surprised to learn that we can already run our project. It will just be a blank screen but as we will be running the game as often as possible to check our progress, let's see how to do that now. You have three options:

  • Run the game on the Emulator on your PC (part of Android Studio)
  • Run the game on a real Android device in USB debugging mode
  • Export the game as a full Android project that can be uploaded to the Play store

The first option is the easiest to set up because we did it as part of setting up Android Studio. If you have a powerful PC you will hardly see the difference between the emulator and a real device. However, screen touches are emulated by mouse clicks and proper testing of the player's experience is not possible.

The second option using a real device has a couple more steps but once set up, is as good as option one and the screen touches are for real.

The final option takes a few minutes (at least) to prepare and then you need to manually put the created package onto a real device and install it.

Probably the best way is to use the emulator to quickly test minor increments in your code and then fairly regularly use USB debugging mode on a real device to make sure things are still as expected. Only occasionally will you want to export an actual deployable package.

Tip

If you have an especially slow PC or a particularly aging Android device, you will be fine just running the projects in this book using just one option or the other. Note that a slow Android phone will probably be OK and cope, but a very slow PC will probably not handle the emulator running games and you will benefit from running the games on your phone/tablet – especially the later games.

For these reasons, I will now go through how to run the game using the emulator and USB debugging on a real device.

Running the game on an Android emulator

Follow these simple steps to run the game on the default Android emulator.

  1. On the Android Studio menu bar select Tools | Android AVD Manager. AVD stands for Android Virtual Device (an emulator). You will see the following window.
    Running the game on an Android emulator
  2. Notice there is an emulator in the list. In my case, it is Pixel API 25 if you are following this sometime in the future it will probably be a different emulator that was installed by default. It won't matter. Click the green play icon shown in the next image and wait while the emulator boots up.
    Running the game on an Android emulator
  3. Now you can see the emulator as shown in the next image. Note also in the next image I have highlighted one of the icons in the control panel to the right of the emulator. Click that icon to rotate the phone into landscape mode ready to run the game.
    Running the game on an Android emulator
  4. Now you can click the play icon on the Android Studio quick-launch bar as shown in the next image and when prompted choose Pixel API 25 (or whatever your emulator is called) and the game will launch on the emulator.
    Running the game on an Android emulator

You're done. Here is what the running game looks like so far:

Running the game on an Android emulator

Clearly, we have more work to do but it is a good start. Let's see how to do the same on a real device and then we can go about building Sub' Hunter further.

Running the game on a real device

The first thing to do is to visit your device manufacturer's website and obtain and install any drivers that are needed for your device and operating system.

Tip

Most newer devices won't need a driver. So you may want to just try the following steps first.

The next few steps will set up the Android device for debugging. Note that different manufacturers structure the menu options slightly differently to others. But the following sequence is probably very close, if not exact for enabling debugging on most devices:

  1. Tap the Settings menu option or the Settings app on your phone/tablet
  2. This next step will vary slightly for different versions of Android. The Developer options menu is hidden away so as not to trouble regular users. You must perform a slightly odd task to unlock the menu option. Tap the About device or About Phone option. Find the Build Number option and repeatedly tap it until you get a message informing you that You are now a developer!
  3. Go back to the Settings menu
  4. Tap Developer options
  5. Tap the checkbox for USB Debugging
  6. Connect your Android device to the USB port of your computer
  7. Click the play icon from the Android Studio toolbar as shown in the next image
    Running the game on a real device
  8. When prompted click OK to run the game on your chosen device.

We are now ready to learn some Java and add real code to the Sub' Hunter project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.121.153