- Learning Java by Building Android Games
- John Horton
- 304字
- 2021-07-23 19:02:35
Setting up the Pong project
Create a new project called Pong
with the same settings as Sub Hunter. This time, call the Activity PongActivity
because that is all it will be an Activity to communicate between the OS and our game engine that will be separate.
Now we will create the three new classes that are required for this game.
- Create a new class called
PongGame
and check the Package Private checkbox then click the OK button. - Create a new class called
Ball
and check the Package Private checkbox then click the OK button. - Create a new class called
Bat
and check the Package Private checkbox then click the OK button.
Now lock the game to full screen and landscape orientation, just as we did for the Sub Hunter game but this time you need to look for the text PongActivity
.
Note
Reminder: locking screen to landscape and full screen.
We want to use every pixel that the player's Android device has to offer so we will make changes to the AndroidManifest.xml
file which allows us to make configuration changes.
Make sure the AndroidManifest.xml
file is open in the editor window.
In the AndroidManifest.xml
file, locate the following line of code: android:name=".PongActivity">
Place the cursor before the closing >
shown above. Tap the Enter key a couple of times to move the >
a couple of lines below the rest of the line shown previously.
Immediately below ".PongActivity"
but before the newly positioned >
type or copy and paste these two lines to make the game run full screen and lock it in the landscape orientation.
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:screenOrientation="landscape"
For further details refer to section Locking the game to full screen and landscape orientation from Chapter 1, Java, Android and Game Development.
We have declared our empty classes and we are ready to get coding.