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();
}
}