public void run() { while (running) { updateGame(); repaint(); try Thread.sleep(30); catch (InterruptedException e) {} } }
Would you like a complete, downloadable example project for a specific genre (runner, shooter, puzzle)?
class GameCanvas extends Canvas implements Runnable { private int playerX, playerY; private boolean shootRequested; private boolean running; java midp 2.0 touch screen games
int dpadCenterX = 40, dpadCenterY = screenHeight - 40; if (Math.hypot(touchX - dpadCenterX, touchY - dpadCenterY) < 35) int dx = touchX - dpadCenterX; int dy = touchY - dpadCenterY; if (Math.abs(dx) > Math.abs(dy)) moveHorizontal(dx); else moveVertical(dy);
Most vendors ignored these until later JTWI/Java Verified phones. Use vendor-specific APIs. Nokia Touch API (S60 5th Ed / S40) // Need: com.nokia.mid.ui.TouchEvent import com.nokia.mid.ui.TouchEvent; import com.nokia.mid.ui.TouchDevice; // In FullCanvas subclass public void pointerPressed(int x, int y) // still works, but better: public void run() { while (running) { updateGame();
protected void pointerReleased(int x, int y) touching = false; onTouchUp(x, y);
Record touch down/up positions to detect direction. Nokia Touch API (S60 5th Ed / S40) // Need: com
(e.g., tower defense, puzzle) Store last tap point and move character toward it.