画面滚动不流畅问题,诸位请进??万分感谢了先。。。

tai_1219 2006-04-22 09:36:48
大家好,问题是,在真机上测试,滚屏不流畅。
现贴出源代码,
有高手指点一下,不胜感谢!!

装入图片资源
public TestCanvas()
{
try
{
layerManager = new LayerManager();
Image mapTitle = Image.createImage("/m.png");
terrain = new TiledLayer(2,80,mapTitle,64,64);
terrain.setCell(0,0,1);
for (int row=0; row<80; row++)
for (int col=0; col<2; col++)
terrain.setCell(col,row,1);
layerManager.append(terrain);
terrainScroll = - (terrain.getCellHeight() * terrain.getRows()) + getHeight();
}
catch(Exception _ex)
{
System.err.println(_ex.getMessage());
}
}
线程
public void run()
{
long l = 0l;
while(threadRun)
{
if(isShown()&&(System.currentTimeMillis() - l >= 40l))
{
l = System.currentTimeMillis();
terrainScroll += 1;
terrain.setPosition(0,terrainScroll);
repaint();
}
}
}

protected void paint(Graphics g)
{
layerManager.paint(g,0,0);
}

感觉在真机上测试,还是不流畅,看了一些资料,说,需要
设置屏幕Buffer,难道说只能这么做吗?

...全文
345 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanhan0615 2006-04-25
  • 打赏
  • 举报
回复
建议在run()中这样试试
while(threadRun)
{
l = System.currentTimeMillis();
terrainScroll += 1;
terrain.setPosition(0,terrainScroll);
repaint();

try
{
Thread.sleep(100);
}
catch(Exception e){}
}
贝壳鱼 2006-04-25
  • 打赏
  • 举报
回复
有的机器已经实现双缓冲了。如果你的动画比较耗费时间,最好加上完整的桢控
xueyong1203 2006-04-25
  • 打赏
  • 举报
回复
哪款机子?
sayigood 2006-04-23
  • 打赏
  • 举报
回复
使用双缓存能使你的画面看的流畅,不错···!
liujun999999 2006-04-22
  • 打赏
  • 举报
回复
应该差不多吧
tai_1219 2006-04-22
  • 打赏
  • 举报
回复
请教Luijun999999,如使用Canvas,自己实现Buffer,效果可能好过GameCanvas的Buffer,可能吗??
liujun999999 2006-04-22
  • 打赏
  • 举报
回复
呵呵,GameCanvas内置的buffer啊,当然要好写
tai_1219 2006-04-22
  • 打赏
  • 举报
回复
Luijun9999999,你的分,稍后给你,再看看,有没有其他好的建议。
tai_1219 2006-04-22
  • 打赏
  • 举报
回复
感谢Luijun9999999,用GameCanvas效果确实要好些了。不过,还是没有达到我想要的理想的效果。给分了。。。
liujun999999 2006-04-22
  • 打赏
  • 举报
回复
用GameCanvas吧

13,100

社区成员

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

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