This works fine for me on Windows, but someone with a Mac tested it and said that they just got a black screen, although they could hear their character moving. repaint() is definitely being called but it isn’t doing it…
Strangely, on a Mac I have (it’s an old PowerPC one with Java 1.5 and OS X 10.4), I get a black screen too but if I resize the browser window or move another window on top of it, it starts working.
public void init() {
setBackground(Color.black);
log("Setting up");
//Initialize the canvas, set up input listeners
log("Starting animator");
animator = new Thread(this);
animator.setName("AnimatorThread");
animator.start();
new Thread(new Runnable()
{
public void run()
{
setIgnoreRepaint(true);
//load some stuff
setIgnoreRepaint(false);
doneLoading = true;
}
}).start();
}
@Override
public void start()
{
}
@Override
public void update(Graphics g)
{
canvas.repaint(); //Updates a VolatileImage stored in the Canvas class
g.drawImage(canvas.getImage(), 0, 0, this);
}
@Override
public void paint(Graphics g)
{
update(g);
}
public void run()
{
log("Current thread is "+Thread.currentThread());
while(Thread.currentThread() == animator)
{
//Process input and so on
repaint();
try {
Thread.sleep(8); //limit FPS
} catch (InterruptedException ex) {
}
}
}
I’ve tried moving code around between init() and start() and paint() and update(), no success.
Anyone see a problem?
Edit: Fixed some code that was copied incorrectly