我制作了一个蛇游戏,我用帆布画蛇,墙壁和食物。
当我在不同的设备上使用它时,对象的大小不一样。
我尝试过使用它:
final float scale = Resources.getSystem().getDisplayMetrics().density;
但它仍然不同,不像以前那样,但仍然不同。
这是一个 htc one x 设备:----------------------这里是 pomp w89 设备:
---
(设备类型的操作非常重要,因为它在我的计算机上的模拟器上有所不同)
代码:
final float scale = Resources.getSystem().getDisplayMetrics().density;
float PART_SIZE= 10*scale;
this.a=new Arena(view,PART_SIZE,33,36,1,0);
竞技场课程:
public static int left;
public static int top;
public static int right;
public static int bottom;
public Arena(LinearLayout view,float snakePartSize,int width,int height,int top,int left) {
//constructor
WALL_SIZE=snakePartSize;
this.left=(int) (view.getLeft()+(top*snakePartSize));
this.top=(int) (0+(top*snakePartSize));
this.right=(int) (this.left+(snakePartSize*width));
this.bottom=(int) (this.top+(snakePartSize*height));
}
public void onDraw(Canvas canvas){
/*draws the walls
*
*/
canvas.drawColor(Color.WHITE);
leftW.setR(left, top, (int) (left+WALL_SIZE), bottom);
topW.setR(left, top,right,(int) (top+WALL_SIZE));
rightW.setR(right, top, (int) (right+WALL_SIZE),(int) (bottom+WALL_SIZE));
bottomW.setR(left, bottom,(int) (right+WALL_SIZE),(int) (bottom+WALL_SIZE));
canvas.drawRect(leftW.getR(),leftW.getP());
canvas.drawRect(topW.getR(),topW.getP());
canvas.drawRect(rightW.getR(),rightW.getP());
canvas.drawRect(bottomW.getR(),bottomW.getP());
}
我该如何解决?感谢