📄 racergamecanvas.java
字号:
/*
* Copyright 2003, 2004 Symbian Ltd.
* For License terms see http://www.symbian.com/developer/techlib/codelicense.html
*/
package demoracer;
/**
* <p>Title: DemoRacer</p>
* <p>Description: Game API Demo for Symbian MIDP 2.0 Book.</p>
* @author Alan Newman - alan@sensibledevelopment.net
* @version 1.0
*/
/*
* This is the class that provides the graphical context for the app.
* It implements the runnanble interface to provide the thread which makes the animation
* it also instatiates the LayerManager class which manages the sprites
* it also creates an "Exit" command which has to be homebaked due to the Canvas being set to "Full".
*/
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
public class RacerGameCanvas extends GameCanvas implements Runnable {
private RacerMidlet midlet;
private RacerLayerManager layerManager;
private Thread thread;
private boolean running;
private final int SLEEP = 0;
public RacerGameCanvas(RacerMidlet midlet) throws IOException {
super(false);
this.midlet = midlet;
layerManager = new RacerLayerManager(this);
}
public boolean isRunning(){return running;}
synchronized void start() {
running=true;
thread=new Thread(this);
thread.start();
}
public void run() {
Graphics graphics=getGraphics();
try {
while (running) {
// draw the current frames for each of the Sprites on screen
paint(graphics);
flushGraphics();
// set the next frame to be displayed and reposition if required.
layerManager.tick();
Thread.sleep(SLEEP);
}
}catch(InterruptedException ie) {
System.out.println(ie.toString());
}
}
synchronized void stop() {
running=false;
}
public void paint(Graphics g) {
layerManager.draw(g);
}
public void keyPressed(int keyCode) {
//Because the GameCanvas as been set to full screen we cannot add Comands to it
//(think this is a bug). Therefore we have had to make our own "Exit" command to
//exit from the MIDlet. This basically detects whether the left hand soft key has
//been pressed and exits the MIDlet.
if(keyCode==-6) {
midlet.releaseResource();
midlet.notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -