Programming Games for Android

Programming Games for Android 04: Running libgdx on the phone

42 videos

238 minutes

Phew. It has taken a little but is finally ready. Let's see, now you're ready to work Android and Android Studio and is all loaded, how can you do to run the game at any time. I like to teach it at first because if at any time someone wants to teach or you want to take the mobile is easy. You see, you have three projects here. In my case, three, maybe you have more according to your choice.

You should have a project called core, which is always created. Here is the game code, but the code is platform independent. That is to say, the game is always in the core. The other projects are the pitchers, dealing convert the core project to work in each of the platforms. They have different libraries to run the same code in each. For example, you should have the Android project,

because if there is little development for Android can do, where you have a launcher for Android, which is nothing more than an application, as if an activity more start the game and puts it on screen as any other Android application. You should also have a draft desktop if you marked it as I said it is more comfortable so try it with emulators. What we have is a standard main,

which it is a pitcher who receives the MainGame and displays it in a window rather than full screen. There is a curious Android folder called assets. There are more folders, such as beef, like any Android application, folder or library that has libraries for Android. But a folder called assets that draws attention. This folder is important to be remembered at all times because this is where you have to

leave the game resources, such as images, or music or whatever you want to use. You android have to be in because unfortunately does not exist another way to compile the project in keeping Android resources elsewhere, so it should be here and will do other projects It is point to the assets folder so they can find the images on their own, because otherwise would not know. This is important because

if ever the game fails and does not open and do not know why and says he can not upload an image, it is probably because it is not set the assets folder. When you execute desktop we see that it is a problem. For now let's see how to run this on each platform. Android is easy because Android Studio and puts Android settings above. You see that in the drop-down you can open and view the settings.

If you give Play will prepare the environment and ask if we run it on a physical mobile if you have plugged in or on an emulator, which it is also convenient because it is displayed on the screen and that's it. I give to Launch Emulator. Choose Nexus 5. I have two emulators installed, I do not know why, but they are equal. Simply giving the OK button opens the emulator. Turning this emulator will take a while because he has to

load all things and has to prepare the system. Fortunately this is x86 emulator so it is faster than an ARM emulator, and it has many libraries below to make it go fast. Still, it takes its own in turn, as a real Android phone, It not just takes little to turn. Once you have it on, that you see that is not so bad. If you drag up

It will eventually show the application of the game. I do not know if ... here it is, Jump Do not Die. As you can see, the game appears. It appears lying because the game is initially set to run horizontally. I do not know personally turn the phone because I do not use the emulator. What I use and I'll teach is how to use the Desktop project. I close the emulator and what I will do is show how to run desktop.

Some will say 'ah, it's easy, desk, is a Java application more. We simply give Run, and that's it, right?' Well, now you'll see that no, it will fail for what I said a minute ago, you have to set the assets folder so you know where it is, because by default does not know. Fortunately when you give Run a configuration is created. Go to Edit Configurations and modifies desktop settings.

Everything is fine but you need to change the Working Directory, you should be like the Android project: putting / android / assets at the end. With this you can change the paths of the images, because they are relative and are from here because if there is not going to notice. You can rename as you are, because it's not something you can not touch, you can touch everything. Now by giving OK, from that moment

giving Run and it will work fine. This is convenient because as shown in a window that does not depend on emulators or anything like that you can tinker with it, touch it, even make computer games with the keyboard and all. With this at least it works, and the good thing is that because anytime you can run if you like, show it to a friend, that always cool at first,

so I want you to know this from the start.

To find new courses, subscribe. There will be no spam, promised :)

About the Author

foto de jotajotavm
José Javier Villena

Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.