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这两个方法,可是为什么画出来的动画还是有重影呢。
...全文
89 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
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());

13,097

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧