GameCanvas 双缓冲
package com.dog;
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
public class Story extends GameCanvas implements Runnable{
BombRen br;
Image story;
int x,y,storyWidth,storyHeight;
Graphics outG;
boolean flag;
byte a = Graphics.LEFT|Graphics.TOP;
public Story(BombRen brIn){
super(false);
flag = true;
x = 0;
y = 320;
br = brIn;
try {
story = Image.createImage("/sister.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Thread(this).start();
}
//public void paint(Graphics g) {
//g.drawImage(story, x,y, a);
//}
public void run() {
while(flag){
y=y-1;
outG = this.getGraphics();
outG.drawImage(story, x, y, a);
this.flushGraphics();
//repaint();
try{Thread.sleep(100);}
catch(InterruptedException e ){
e.printStackTrace();
}
}
}
}
我已经用了getGraphics ,flushGraphics这两个方法,可是为什么画出来的动画还是有重影呢。