Hi,
I wrote a litte puzzle game (a remake of the classic Atomix).
Screenshot (127 kb) :
http://kh.weltregierung.de/trin/uploads/jatomix.png (slow)
http://domfree.de/trin/uploads/jAtomix.png (copy&paste link)
The problem is, that on startup the drawing of the background image, which is a 682x451x64 gif with 76.7 kb, is horrible slow. It takes about 10 seconds until the image appears.
It would be nice, if someone could give me some advice, how to speed up the drawing process.
This is a sample of the code I use.
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.*;
public class test {
Image bg;
Screen screen;
public test() {
Frame frame = new Frame("test");
frame.addWindowListener(new MyWindowAdapter());
screen = new Screen();
frame.add(screen);
frame.setSize(675, 455);
frame.setResizable(false);
frame.setVisible(true);
bg = Toolkit.getDefaultToolkit().getImage("gifs/backgr.gif");
}
public class Screen extends Canvas {
// doublebuffering
Image dbImage;
Graphics dbg;
public void update(Graphics g) {
// initialize buffer
if (dbImage == null) {
dbImage = createImage(this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics();
}
// clear screen in background
dbg.setColor(getBackground());
dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
// draw elements in background
dbg.setColor(getForeground());
paint(dbg);
// draw image on the screen
g.drawImage(dbImage, 0, 0, this);
}
public void paint(Graphics g) {
// draw background
g.drawImage(bg, 0, 0, this);
}
}
public static void main(String args[]) {
test jA = new test();
}
class MyWindowAdapter extends WindowAdapter {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
}
}
much thx