views:

42

answers:

2

In JGame, the method setBGImage() is supposed to change the background image. This works when I'm setting the background image for the first time at the start of the initialization. However, when I call the same method later to change the background image, it seems to do nothing. What am I doing wrong?

Here's some example code to show you what I mean:

import jgame.*;
import jgame.platform.*;

public class Test extends JGEngine{
    public static void main(String[] args) {
        new Test();
    }

    public Test(){
        super();
        initEngine(640,480);
    }

    public void initCanvas(){
        setCanvasSettings(10,6,64,80,null,JGColor.white,null);
    }

    public void initGame(){
        setFrameRate(35,2);
        defineMedia("media.tbl");
        doTestBackground();
    }

    /* Demonstrates the bug */
    void doTestBackground(){
        new Thread(new Runnable(){
            public void run(){

                setBGImage("bg1");

                /* If it's put here, then it works perfectly:
                   setBGImage("bg2"); */

                try{
                    Thread.sleep(2000);
                }
                catch(Exception e){}

                /* If it's put here it doesn't work!
                   The background SHOULD change here but it doesn't */
                setBGImage("bg2");

            }
        }).start();
    }
}
A: 

Perhaps you are running into problems with using the wrong thread? Generally, the AWT thread is used to change components (in the Swing framework).

Try using SwingUtilities.invokeLater(new Runnable() { public void run() { setBGImage("things");} } );

Mike
Nope, this isn't the problem.
aplm
A: 

If you still want some answer. Here it is: http://installsteps.blogspot.com/2010/10/jgame-java-game-engine.html

m.e.