If you need to make some animation in Java ME Canvas, you must use a Game Loop using multithreading.
This code will be useful as a template for doing such animation.
class MyAnimation extends Canvas implements Runnable {
private Thread thread;
private boolean executing;
private final int SLEEP = 200;
public void start() {
executing=true;
thread = new Thread(this);
thread.start();
}
public void stop() {
executing = false;
}
public void run() {
// Do some initial action
while (executing) {
// move objects or sprites to the next animation frame
repaint();
serviceRepaints();//repaint is a just a request whereas
//servicerepaint is a command to repaint all
//ur pending repaint requests
}
try {
// Send the thread to "sleep" for a couple of milliseconds
Thread.sleep(SLEEP);
} catch(Exception e) {}
}
public void paint() {
// Draw objects on screen
}
}
No related wiki articles found