I use a random integer to determine which image will be
fallen (i.e: just like Tetris), so in the run method I apply:
public void run()
{
long st=0;
long et =0;
while(conti) {
st = System.currentTimeMillis();
y = y + 10;
repaint();
doDraw3(g);
randInt = Math.abs(rand.nextInt()%2);
System.out.println("name ID = "+nameID);
et = System.currentTimeMillis();
if ((et-st)<rate)
{
try { Thread.sleep(rate-(et-st));} catch (Exception exp) {}
}
}
}
For the paint method i.e doDraw3(g):
public void doDraw3(Graphics g) {
g.setColor(0x00000000);
g.fillRect(0, 0, 300, 300);
try {img00 = Image.createImage("/00.png");
img01 = Image.createImage("/01.png");
}catch(Exception e) {}
if(randInt==0) {
nameID = “0”;
s0=createNumber("/00.png");
}
else if(randInt==1) {
nameID = “1”;
s1=createNumber("/01.png");
}
}
where s0 and s1 are sprites.
The result is the image is fallen from the top to the bottom, but the image is changing for every MillisSecond during the falling process.
I want to fix them. Do I have something is go wrong? ??? Thanks for your reply!