Java Reference
In-Depth Information
int x = mBorder;
int y = mBorder;
int w = width - mBorder * 2;
int h = height - mBorder * 2;
for (int i = 0; i < 8; i++) {
g.setGrayScale((8 - i) * 32 - 16);
g.fillArc(x, y, w, h, mTheta + i * 10, 10);
g.fillArc(x, y, w, h, (mTheta + 180) % 360 + i * 10, 10);
}
}
public void run() {
while (mTrucking) {
mTheta = (mTheta + 1) % 360;
repaint();
try { Thread.sleep(mDelay); }
catch (InterruptedException ie) {}
}
}
}
The Game API offers another option for running an animation. In the next chapter, you'll
see how Sweep 's simple animation can be implemented using GameCanvas .
Summary
We've covered a lot of ground in this chapter. The Canvas class provides a low-level interface for
games or other demanding applications. You can draw shapes, text, and images on a Canvas
using the Graphics class. Furthermore, you can receive detailed input information about key
and pointer events. Game actions are simple generalized input methods based on key events.
Finally, you should understand the multithreading issues with repainting and event callbacks.
Lengthy processing should be placed in a separate thread so that it doesn't bring the system-
owned user-interface thread to a grinding halt. Animations can use Display 's callSerially()
method to synchronize with the user-interface thread, although more commonly they will be
implemented using a separate animation thread. The next chapter details the Game API.
Search WWH ::




Custom Search