While I was in school, my assignments were always due on Sunday. Therefore, it feels only natural to reflect on my current ambitions on a Sunday. Due to the holidays, I do not actually have much going on. However, I have been working on learning the Android Operating System in hopes of developing a game, Swap Meet Server, and maybe making a dollar or two while building my resume.
As mentioned above, I did not actually accomplish much this week. I did manage to learn a lot of basic programming functions for creating Android applications. I also managed to setup my own game loop, which I will discuss here.
A game loop is a function within a program that is made to keep the program running while appropriately handling any operating systems that could interrupt the program. Most applications run the thick of the application in a loop. This is because a procedural program without a loop would run all of its code then exit. By putting the majority of the code in the loop, we are able to control when the program ends by having it wait for some sort of quit message. In terms of Windows operating systems, a quit message would be triggered by the Alt+F4 or clicking the red X in the corner of the window.
The other reason for the game loop is to handle other events from the operating system; usually without interrupting the game. My experience with Android so far has taught me that I really only need to be concerned with three events that might interrupt the game. These three events are when there is an incoming call, when the battery is dead, or when the program loses focus. Preferably, in the cases when the battery has not died, the game is put in a pause state. This way, if the user comes back to the game, they can pickup where they left off. The pause state can be activated very simply and is actually a usual function for an Android application. Implementing it is easy.
Now, when the battery dies, you have a different situation on your hands. You will not be able to recover from a pause when turning the phone back on, as the application will have been closed forcibly. Luckily, most Android products actually shutoff before the battery dies. Even if the battery has only a fraction of a percent of juice left, there is usually enough processing time left to exit the program gracefully. In the case that a phone being switched off is adamant, it is best to call whichever quit method you have for the application, which should release all assets before closing the program.
If these things are not happening during the life cycle of an Android application, there should be nothing else happening to interrupt the program. While the application is running, the loop processes continually. To the user, this appears as the application running seamlessly. The main purpose of the loop is to update the graphics, check for user input, and output the correct information. Again, if this is done correctly, it appears to the user as an application running.
For my specific project, the loop does not do much yet. I have the application open to the loop, which cycles a splash screen and menu screen continuously until the user exits the program. Like I said, I did not accomplish much, but we should not discount this progress. The game loop is the foundation of your game project. It is essential that you have a proper setup for your game loop if you hope for your product to run successfully.