GameCanvas 双缓冲

ice_wating 2011-02-26 10:04:28
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这两个方法,可是为什么画出来的动画还是有重影呢。
...全文
47 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ice_wating 2011-02-28
很感谢2,3楼,改的时候搞错了,应该是
outG.setColor(0xffffff);
outG.fillRect(0, 0, this.getWidth(), this.getHeight());
而不是
g.setColor(0xffffff);
g.fillRect(0, 0, this.getWidth(), this.getHeight());

回复
sihonglaoren 2011-02-28
每次绘制之前没有清屏
g.setColor(0xffffff);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
回复
ice_wating 2011-02-28
还是不太懂,我把g.setColor(0xffffff);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
放在了flushiGraphics()前,可是好时会有重影,而且画面闪得非常厉害
回复
runer 2011-02-27
flushGraphics()之前先清除上次的图像就ok了

回复
麦田捕手 2011-02-27
每次绘制之前没有清屏
		g.setColor(0xffffff);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
回复
相关推荐
发帖
J2ME
创建于2007-09-28

1.3w+

社区成员

Java J2ME
申请成为版主
帖子事件
创建了帖子
2011-02-26 10:04
社区公告
暂无公告