HUD Update Problem

I have created a HUD (a really nice one) from the tutorial and so have all the usual stuff. Unfortunately, while it draws the first frame perfectly, its refuses to update when I update the image, reset the texture and update the quad. I am clearly missing something crucial. Any ideas?

I've been working with HUDs lately too (in jME 1.x).  Perhaps if you post a code-slice I, or someone else, can spot the problem.  But usually, if the HUD isn't updating properly its due to the TextureState not being deleted before updating.


That sounds like it might be the problem. I'll try it and get back to you. Thanks.

do you call hudNode.updateRenderstate() ?

Yep. Here is the code. The other fix didn't work.



    private class PaintThread extends Thread {

        @Override

        public void run() {

            while (true) {

                try {

                    sleep(DELAY);

                    refreshImage();

                    update();

                }

                catch (InterruptedException ex) {}

            }

        }

    }



    public void refreshImage() {

        Graphics2D g = image.createGraphics();

        paint(g);

        g.dispose();

        byte buffer[] = (byte[]) image.getRaster().getDataElements(0, 0, width, height, null);

        scratch.clear();

        scratch.put(buffer, 0, buffer.length);

        scratch.rewind();

        setData(scratch);

    }



    public void paint(Graphics2D g) {

        if (firstTime) {

            prepareDisplay(g);

            firstTime = false;

        }

        drawDisplay(g);

    }



    public void update() {

        textureState.setNeedsRefresh(true);

        textureState.setTexture(texture);

        quad.setRenderState(textureState);

        quad.updateRenderState();

     }



The textureState.delateAll() caused a null pointer exception, so I removed it.

Any ideas. It's still not working even after replacing the thread with a call from simpleUpdate() to update the HUD. In fact, now that the update doesn't occur within the first frame, most of the HUD doesn't even draw. Any clues, please?

Okay, I got some of it going and I think I have clue as to what was wrong. Clearly, prior to simpleUpdate() being called, the texture states are initialised. If you call deleteAll() prior to this, you get a null pointer exception. When I re-added the deleteAll() after the local HUD update() had been called from simpleUpdate(), it now works, well partially. By the way, I am using jME 1.0 and I'm expecting great things the jME 2.0 when it is released.

Got all of it going (with few a few bugs that are only I/O related). Thanks for your help. All the advice was good, in the right context. Those writing a HUD in the future, make sure you update it ONLY via update(), and use deleteAll() and updateRenderState() to ensure it renders properly.