Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Java by Building Android  Games

You're reading from   Learning Java by Building Android Games Learn Java and Android from scratch by building six exciting games

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher
ISBN-13 9781788839150
Length 774 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
John Horton John Horton
Author Profile Icon John Horton
John Horton
Arrow right icon
View More author details
Toc

Table of Contents (28) Chapters Close

Preface 1. Java, Android and Game Development FREE CHAPTER 2. Java: First Contact 3. Variables, Operators and Expressions 4. Structuring Code with Java Methods 5. The Android Canvas Class – Drawing to the Screen 6. Repeating Blocks of Code with Loops 7. Making Decisions with Java If, Else and Switch 8. Object-Oriented Programming 9. The Game Engine, Threads, and The Game Loop 10. Coding the Bat and Ball 11. Collisions, Sound Effects and Supporting Different Versions of Android 12. Handling Lots of Data with Arrays 13. Bitmap Graphics and Measuring Time 14. The Stack, the Heap, and the Garbage Collector 15. Android Localization -Hola! 16. Collections, Generics and Enumerations 17. Manipulating Bitmaps and Coding the Snake class 18. Introduction to Design Patterns and much more! 19. Listening with the Observer Pattern, Multitouch and Building a Particle System 20. More Patterns, a Scrolling Background and Building the Player's ship 21. Completing the Scrolling Shooter Game 22. Exploring More Patterns and Planning the Platformer Project 23. The Singleton Pattern, Java HashMap, Storing Bitmaps Efficiently and Designing Levels 24. Sprite-sheet animations, Controllable Player and Parallax Scrolling Backgrounds 25. Intelligent Platforms and Advanced Collision Detection 26. What next? Index

Locking the game to full-screen and landscape orientation

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. If you followed along with the previous section it will be already.

In the AndroidManifest.xml file, locate the following line of code:

android:name=".SubHunter">

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 above.

Immediately below ".SubHunter" 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"

This is a fiddly set of steps and it is the first code we have edited in the book so here I am showing you a bigger range of this file with the code we just added highlighted amongst it.

…
<activity android:name=".SubHunter"
   android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
   android:screenOrientation="landscape"
   >
   <intent-filter>
      <action android:name="android.intent.action.MAIN" />

      <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>
…

Tip

The code we have just written and the rest of the contents of AndroidManifest.xml we call XML (extensible markup language). Android uses XML for several different configurations. It is not necessary to learn this language as to make all the projects in this book this minor modification is all we will ever need to do.

Now our game will use all the screen space the device makes available and the screen has been locked in landscape mode even if the player holds their device in portrait orientation.

You have been reading a chapter from
Learning Java by Building Android Games - Second Edition
Published in: Aug 2018
Publisher:
ISBN-13: 9781788839150
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime