donderdag 31 maart 2011

Skeleton game code.

I found this code on java gaming.


import java.applet.*;
import java.awt.*;
public class Game extends Applet implements Runnable {
    Image buffer; // faster than BufferedImage, I've experienced
    Thread me;
    public void init() {
        buffer = createImage(getWidth(),getHeight());
        me = new Thread(this);
        me.start();
    }
    public void run() {
        while (me.isAlive()) {
            // game logic here
            if (getGraphics() != null) paint(getGraphics());
            try {
                Thread.sleep(10);
            }
            catch (InterruptedException e) {}
        }
    }
    public void paint(Graphics g) {
        Graphics gfx = buffer.getGraphics();
        // work your drawing magic here
        g.drawImage(buffer,0,0,null);
    }
}

Geen opmerkingen:

Een reactie posten