Custom Search
Laporkan jika ada link yang bermasalah
[ HOME ] [ FORUM ] [ JAVA ] [ JARINGAN KOMPUTER] [ OCEAN ] [ SEARCH ]

Thursday, February 12, 2009

Implementasi Sederhana Class canvasGame

public class canvasGame extends GameCanvas implements Runnable {
// Constructor and initialization
public canvasGame() {
super(true);
...
}

// Automatically start thread for game loop
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}

public void stop() { isPlay = false; }
// Main Game Loop
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
input();
drawScreen(g);
try { Thread.sleep(delay); }
catch (InterruptedException ie) {}
}
}

// Method to Handle User Inputs
private void input() {
int keyStates = getKeyStates();

// Left
if ((keyStates & LEFT_PRESSED) != 0)
currentX = Math.max(0, currentX - 1);
...
}

// Method to Display Graphics
private void drawScreen(Graphics g) {
...
flushGraphics();
}
}

1 comment:

  1. gan, tolong dong.. mau tanya ni.

    apa netbeans 6.7.1 bisa buatgame untuk skripsi??

    caranya?

    trims

    ReplyDelete