我不确定为什么我的代码(稍微)滞后,并且不能以相同的速度可靠地运行——我想我一定是做错了什么,因为许多其他游戏都非常流畅。我的 Renderer 类中的相关代码在这里:
public void drawPicString(Location location, String string,
RenderParams params) {
//canvas.save();
float rawX = location.getX();
float rawY = location.getY();
Bitmap rawbit = myImageCache.get(string);
//Bitmap rawbit = provider.getBitmap(string);
float thisWidth = rawbit.getWidth();
float thisHeight = rawbit.getHeight();
if(params.shouldResize){
thisWidth = params.resizex;
thisHeight = params.resizey;
}
float leftx = rawX-(thisWidth/2);
float topy = rawY-(thisHeight/2);
Matrix matrix = new Matrix();
matrix.setTranslate(leftx, topy);
if(params.shouldResize){
float toScaleY = ((float)thisHeight)/rawbit.getHeight();
float toScaleX = ((float)thisWidth)/rawbit.getWidth();
matrix.preScale(toScaleX, toScaleY);
}
if(params.shouldRotate){
matrix.preRotate((float)Math.toDegrees(params.myangle),(float)(thisWidth/2.0),(float)(thisHeight/2.0));
}
canvas.drawBitmap(rawbit, matrix, paint);
}
我能想到的唯一相关信息是 myImageCache 是位图的缓存,因此它不必在每次绘制它们时都从资源中获取它们。“画布”是在表面视图上的画布绘图,在绘图开始之前的每一帧都传递给它。
提前感谢您的任何想法!