In Practice 1
Let's write an example for this fine API. We want to keep track of ten fingers at most there's no device yet that can track more, so we are on the safe side here . Android will assign pointer identifiers from 0 to 9 to these fingers in the sequence they touch the screen. So we keep track of each pointer identifier's coordinates and touch state touching or not , and output this information to the screen via a TextView. Let's call our test activity MultiTouchTest. Listing 4-4 shows the complete...
Mipmapping
If you've played around with our previous examples and let the cube move further away from the camera, you might have noticed that the texture starts to looks grainy and full of little artifacts the smaller the cube gets. This effect is called aliasing, a prominent effect in all types of signal processing. Figure 11-8 shows you the effect on the right side and the result of applying a technique called mipmapping on the left side. Figure 11-8. Aliasing artifacts on the right the results of...
S 1
Screen classes, 96-97, 236, 285, 287, 298, 352 Screen density, 115 Screen implementations, 97-98, 286-288, 297, 302, 352 Screen instances, 98 Screen interface, 227 screen resolution, 163-164 Screen.dispose method, 98 screenOrientation attribute, 107, 113 Screen.pause method, 98 Screen.present method, 98, 220 Screen.render method, 278 Screen.resume method, 98, 284 screens Droid Invaders game, 580 and game design, 64-70 handling different sizes and resolutions, 210-215 aspect ratios, 211-212...
The Pool Class Because Reuse is Good for You
What's the worst thing that can happen to us as Android developers World-stopping garbage collection If you look at the Input interface definition in Chapter 3, you'll find the methods getTouchEvents and getKeyEvents . These return lists of TouchEvents and KeyEvents. In our keyboard and touch event handlers, we'll constantly create instances of these two classes and store them in lists internal to the handlers. The Android input system fires a lot of those events when a key is pressed or a...
Processing Key Events
After the insanity of the last section, we deserve something dead simple. Welcome to processing key events. To catch key events, we implement another listener interface, called OnKeyListener. It has a single method called onKey , with the following signature public boolean onKey View view, int keyCode, KeyEvent event The View specifies the view that received the key event, the keyCode argument is one of the constants defined in the KeyEvent class, and the final argument is the key event itself,...
GLGame Implementing the Game Interface
In the previous chapter, we implemented the AndroidGame class, which ties together all the submodules for audio, file I O, graphics, and user input handling. We want to reuse most of this for our upcoming 2D OpenGL ES game, so let's implement a new class called GLGame that implements the Game interface we defined earlier. The first thing you will notice is that we can't possibly implement the Graphics interface with our current knowledge of OpenGL ES. Here's a surprise we won't implement it....
Using the OBJ Loader
To demonstrate the OBJ loader, I've rewritten the last example and created a new test called ObjTest along with an ObjScreen. I copied over all the code from the previous example and only changed a single line in the constructor of ObjScreen cube ObjLoader.Iood glGame, cube.obj So, instead of using the createCube method which I removed , we are now directly loading a model from an OBJ file called cube.obj. I created a replica of the cube we previously specified programmatically in createCube in...
The GameScreen Class 1
Once the game transitions to the GameScreen class the player can immediately start playing without having to state that she is ready. The only states we have to care for are tthese The running state where we render the background, the world, and the UI elements as in Figure 12-4. The paused state where we render the background, the world, and the paused menu, again as in Figure 12-4. The game-over state, where we render pretty much the same thing. We'll again follow the same method we used in...
Implementing an OBJ Loader
Our plan of attack will be to load the file completely into memory and create a string per line. We will also create temporary float arrays for all the vertex positions, texture coordinates and normals we are going to load. Their size will be equal to the number of lines in the OBJ file times the number of components per attribute that is, two for texture coordinates or three for normals. By this we overshoot the necessary amount of memory needed to store the data, but that's still better than...
Setting Up the Development Environment
The Android SDK is pretty flexible and integrates well with a couple of development environments. Purists might choose to go all hard-core with command-line tools. We want things to be a little bit more comfortable, though, so we'll go for the simpler, more visual route using an IDE integrated development environment . Here's the grocery list of software you'll need to download and install in the given order The Java Development Kit JDK , version 5 or 6. I suggest going for 6. The Android...
Genres To Each Ones Taste
At the start of your project, you usually decide what genre your game will belong to. Unless you come up with something completely new and previously unseen, chances are high that your game idea fits into one of the broad genres currently popular. Most genres have established game mechanic standards e.g., control schemes, specific goals, etc. . Deviating from these standards can make a game a great hit, as gamers always long for something new. It can also be a great risk, though, so consider...








