Game Dev with Android
A{} N{} D{} R{} O{} I{} D
Game Dev with Libdgx

Homepage | Tutorials | Blog



Feb 2024

Libgdx with Android For Game Dev

Game Dev Tutorial: Manifest - Game Dev: Squared Image
Game Dev -All Game Dev Tutorials Here

For this tutorial, we are going to create a new Game App, and add a squared image to it; 256 x 256 in size, and add a blue background color using the rgb color codes. We are also going to discuss the coding in the 'manifest.xml' file, which has certain elements you can change for your game app.

App Shot

Manifest Code: Squared Image

game dev tutorial, manifest xml and squared image

First, we must create our new Mobile Game App, select 'Create New Project', from your 'AppProjects' hierachy; make certain at top of file hierachy it says: /storage/emulated/0/AppProjects, and then you select Mobile Game, and New Mobile Game, enter the app name "Manifest Code:Squared Image', and package name 'com.aac.Gamedev_code'. Once you select 'Create', the new game app screen will open in the AIDE coding editor.
The code for this tutorial is at the Example Code section this page. Just select to copy and paste all code on the 'MyGdxGame.java' page, or edit where required.

Coding Our Game


In our code, we first add our import statements as shown in this next image.

game dev tutorial, manifest xml and squared image

Then, we add our variables -'texture' and 'batch' - Spritebatch, as seen in this next image.


Next, in our Create method we add our texture image name - which is the 'forest_image.jpg', as shown in the image. And, we include the Spritebatch for that image. And, we know from previous tutorials, that the 'Gdx.files,internal', is the assets folder where we put all our game app images. Our image is sized 256 x 256, a squared image, typical of image sizes used in Libgdx game dev.

Also, we add our code at Render method, which is the drawing of our texture(image) to the screen. Our background color is also coded in the Render method; for this app we selected a blue color and used rgb color codes to code it as this: 0/255f, 191/255f, 255/255f, 1



Game Image

For our game, we add one image, 'forest_image.jpg', which you can download/save from the Example Code section on this page. Then, paste it into your device File Manager, and from there, copy/paste it into the 'gdx-game-android/assets' folder of your App Project- Manifest Code: Squared Image


AndroidManifest.xml

In our first tutorial, we mentioned the various screens that are used in the making of your mobile game app, including those in the 'gdx-game-android' file hierachy. Here we discuss the 'AndroidManifest.xml' file. For game dev, this file is used for a number of reasons, including:

Changing your app icon to a customized one, setting your SDK target numbers, and, version code number update.
For this tutorial, we will provide an explanation of these elements that you can change if you want to.



App Icon - Customize

The android system by default uses the 'ic_launcher.png',(little green android person) for the launch your app icon. You can however, change it to a customized one. This is coded at the AndroidManifest.xml file.
Adding your own app launch icon is easy to do. You must first create an image that should be at least 512 x 512 in size. Then you can name it other than the default, ic_launcher image used now. Example: 'game_icon.png', put this image in the 'drawable-hdpi' folder at gdx-game-android/res folder of your app project, and put the same name at 'android:icon', in the Application element of your AndroidManifest.xml file.

Now RUN your app, and the new icon is shown in your app icons for that game app.

Things to Note:

If you are targeting larger devices with your android mobile game, then you can add larger images to these; 'drawable-ldpi', and 'drawable-mdpi' folders. The android system will grab either of these depending on the screen size of the device your game is installed on. If you do target larger devices but don't add the appropriate sized icons, the system will use the 512x512 one and just adjust it to the screen size, which may or may not look good. And, if you do add additional image sizes, make sure to name them all the same as the first one - in this case our example: 'game_icon.png'.

Mipmap folders can also be used(created) to hold your game and non game app icon images. Because these are typically smaller images they are often used in mobile game apps for performance reasons. They follow the same process, just create/name your Mipmap folders accordingly and add your mipmap images. The Android system simply grabs whatever image is suitable for the device screen size.
For additional reading on mipmaps, goto our tutorial, Mipmaps for Icons - Game Apps

SDK Versions are added by default with our template game app that we use to make our Android mobile game apps. So, the version numbers you see are probably uptodate, as AIDE, is usually uptodate with the most recent Android platform versions. However, you can change these as you like, which would likely be based on a particular 'code class' you add that might require a more recent SDK number.

Version Code and Version Name

The app version code and version name, are also something you can change in the manifest file. Both are usually added before you RUN for the final build of your app code. The version name, '1.0'(default setting), can be up to 50 characters, and is usually not updated once set. The version code, however, does get updated with each new update or release of your app, and by default is set at '1', as shown in the image of the AndroidManifest.xml file.
The 'appname.apk', is the file that gets uploaded to an app store(appname being the actual name of your App Project).
For an example; you make a game app, and then you add more content to your game, so you want to now publish the newly updated game. This is when you would update the version code. Once you add your new content you would change this to '1.1'(or whatever number sequencing you choose), and then RUN the code to build your apk with the newly updated content. Now at the app store, your game app has 2 versions, '1', and '1.1'. This can also be used to distinguish free app versions from paid ones.

Summary

In this tutorial, we added a squared image and added a blue background to our game screen. We discussed the AndroidManifest.xml file. The AndroidManifest.xml file is located by clicking into the gdx-game-android file folder. We mentioned some of the elements that can be changed in this file: app icon, SDK targets, version code and version name; others include; adding app permissions(internet, wifi), page labels, and adding additional activities to our app. We know we can add additional activities in non game Android apps, but for mobile game apps, we only use one activity. Running several activities would really lag our game's performance. We can however, add 'game screens', which are each handled by the libgdx framework. This provides for much better efficiency in our game.


EXAMPLE CODE - Code For This Tutorial.

JUST copy and paste to update your code.

Example Code:
Copy Paste the Code


App Image(s); for this tutorial, 1 image

Save to your device name the image:
forest_image.jpg



AndroidAppCoding.com - GameDev, All Rights Reserved.
All images posted on this Website are Copyrighted © Material.