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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| public void init() { setBackground(Color.black); log("Setting up"); log("Starting animator"); animator = new Thread(this); animator.setName("AnimatorThread"); animator.start();
new Thread(new Runnable() { public void run() {
setIgnoreRepaint(true); setIgnoreRepaint(false);
doneLoading = true; } }).start(); } @Override public void start() { } @Override public void update(Graphics g) { canvas.repaint(); 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) { repaint(); try { Thread.sleep(8); } 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