开发者

Changing background image in JGame

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);
                }
               开发者_C百科 catch(Exception e){}

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

            }
        }).start();
    }
}


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


FYI, this setBGImage behaviour is a bug that was fixed in version 3.4. Since 3.4, setBGImage correctly updates the screen.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜