我正在开发一款2D安卓游戏,我已经实现了自定义视图。现在,我使用了将近50个比率来确定各种游戏元素的位置,如:
int posX = screenWidth / 3;
但是,我认为使用固定数量的单位会更容易,并相应地进行缩放:
public class ScaleCanvas {
private static final int WIDTH = 100;
private static final int HEIGHT = 100;
private int mUnitPixels;
ScaleCanvas(int pWidth) {
mUnitPixels = pWidth / WIDTH;
}
public void drawBitmap(Canvas canvas, Bitmap bitmap, int pX, int pY, Paint paint) {
canvas.drawBitmap(bitmap, pX * mUnitPixels, pY * mUnitPixels, paint);
}
public void drawBitmap(Canvas canvas, Bitmap bitmap, Rect src, Rect dst, Paint paint) {
canvas.drawBitmap(bitmap, new Rect(src.left * mUnitPixels, src.top * mUnitPixels, src.right * mUnitPixels,
src.bottom * mUnitPixels), new Rect(dst.left * mUnitPixels, dst.top * mUnitPixels, dst.right
* mUnitPixels, dst.bottom * mUnitPixels), paint);
}
}
对于以50 FPS运行的游戏,是否会严重降低性能,从每个帧调用此类的几个drawBitmap()函数?如果是这样,有哪些替代方案?
答案 0 :(得分:0)
如果您担心性能问题,我建议您使用OpenGL ES或LibGDX而不是自定义视图。