Hi!
I'm using the Processing lib with mt4j (a multitouch java framework)
Atm I'm trying to display an image on the background and reloaded it every few milliseconds so that it looks like a video.
The image file is updated and saved from another program every 30 milliseconds(and works fine).
my code so far looks like this:
the main class
Code:
public OTscene(MTApplication mtApplication, String name) {
super(mtApplication, name);
this.pa = mtApplication;
im = pa.loadImage(System.getProperty("user.dir") + File.separator + "1.jpg");
// Mt4j bit to add the image in the backgorund
img = new MTBackgroundImage(pa, im, true);
backgroundLayer = new MTComponent(pa);
backgroundLayer.addChild(img);
canvas = this.getCanvas();
canvas.addChild(backgroundLayer);
//Thread Class to reload the image
BackgroundUpdate updateBack = new BackgroundUpdate(this);
Thread a = new Thread(updateBack);
a.start();
and the run method
Code:
public void run(){
while(true){
//reload the updated image
im = pa.loadImage(System.getProperty("user.dir") + File.separator + "1.jpg");
//mt4j bit
img = new MTBackgroundImage(pa, im, true);
backgroundLayer.removeChild(0);
backgroundLayer.addChild(img);
//Wait a bit
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
the first time, the image loads without any problem and it shows up, then when it tries to load from the second time onwards it just gives me a blank screen..
Does anybody know what I'm doing wrong or if there is any other better way of doing this thing?
cheers!