如何使画布中绘制的图像对所有屏幕尺寸都有效?我的代码,但它不起作用,绘制的游戏屏幕对于小屏幕来说太大了,对于大屏幕来说太小了,我已经尝试了一切,但没有任何效果,我希望画布根据屏幕的大小进行缩放
这是我得到的结果和期望的结果:https://imgur.com/a/bSnGfov
以下是我的游戏画布代码:
public class CanvasView extends View {
Me me;
public int width;
public int height;
public int fx,fy,zx,zy;
int[][]lines;
private Bitmap pme, wall,finish,redlock,redkey,bluelock,bluekey,greenlock,greenkey ,mBitmap,white,c1,c2,c3,c4,c5,c6,c7
,c8,c9,c10,c11,c12;
private Canvas mCanvas;
private Path mPath;
Context context;
private Paint p;
private int mx, my,character;private int dir;
private static final float TOLERANCE = 5;float bb;string bbb; int sz;int fz;
public CanvasView(Context c,int[][] l,Me m,int mxx,int myy,int chara) {
super(c);
lines=l;
mx = mxx;
my = myy;
context = c;
fx=6;fy=6;zx=0;zy=0;
me = m;
character=chara;
mPath = new Path();
p = new Paint();
p.setAntiAlias(true);
p.setColor(Color.BLACK);
p.setStyle(Paint.Style.STROKE);
p.setStrokeJoin(Paint.Join.ROUND);
p.setStrokeWidth(4f);
}
// override onSizeChanged
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
// your Canvas will draw onto the defined Bitmap
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
}
ITMISS
相关分类