Game Development Reference
In-Depth Information
The first call gets rid of the activity's title bar. To make the activity go full-screen and thus
eliminate the notification bar as well, we call the second method. Note that we have to call these
methods before we set the content view of our activity.
Listing 4-11 shows a very simple test activity that demonstrates how to go full-screen.
Listing 4-11. FullScreenTest.java; Making Our Activity Go Full-Screen
package com.badlogic.androidgames;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class FullScreenTest extends SingleTouchTest {
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window. FEATURE_NO_TITLE );
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
WindowManager.LayoutParams. FLAG_FULLSCREEN );
super .onCreate(savedInstanceState);
}
}
What's happening here? We simply derive from the TouchTest class we created earlier and
override the onCreate() method. In the onCreate() method, we enable full-screen mode and
then call the onCreate() method of the superclass (in this case, the TouchTest activity), which
will set up all the rest of the activity. Note again that we have to call those two methods before
we set the content view. Hence, the superclass onCreate() method is called after we execute
these two methods.
We also fixed the orientation of the activity to portrait mode in the manifest file. You didn't forget
to add <activity> elements in the manifest file for each test we wrote, right? From now on,
we'll always fix it to either portrait mode or landscape mode, since we don't want a changing
coordinate system all the time.
By deriving from TouchTest , we have a fully working example that we can now use to explore
the coordinate system in which we are going to draw. The activity will show you the coordinates
where you touch the screen, as in the old TouchTest example. The difference this time is that
we are full-screen, which means that the maximum coordinates of our touch events are equal to
the screen resolution (minus one in each dimension, as we start at [0,0]). For a Nexus One, the
coordinate system would span the coordinates (0,0) to (479,799) in portrait mode (for a total of
480×800 pixels).
While it may seem that the screen is redrawn continuously, it actually is not. Remember from
our TouchTest class that we update the TextView every time a touch event is processed. This, in
turn, makes the TextView redraw itself. If we don't touch the screen, the TextView will not redraw
itself. For a game, we need to be able to redraw the screen as often as possible, preferably
within our main loop thread. We'll start off easy, and begin with continuous rendering in the
UI thread.
Search WWH ::




Custom Search