0
這是我的代碼在Sprite
類:比例位圖SurfaceView
public class Sprite {
int x, y, vx, vy;
private Bitmap texture;
public Sprite(Bitmap texture) {
this.texture = texture;
}
public int getWidth() {
return texture.getWidth();
}
public int getHeight() {
return texture.getHeight();
}
public void draw(Canvas c) {
c.drawBitmap(texture, x, y, null);
}
}
與background.draw(c);
我畫的背景。但是背景比屏幕大...
如何將它縮放到屏幕大小?
當我不想要顏色,我必須在那裏寫'null'? – Stupe 2012-08-07 12:05:45
你可以使用下面的方法:public void drawBitmap(Bitmap bitmap,Rect src,RectF dst,Paint paint),如果你不需要剪裁,將它傳遞給src null,然後創建一個dst矩形來定義繪製位圖的區域(其左上角將設置位圖的左上角及其寬度,高度將設置位圖的寬度和高度) – victorvartan 2012-08-07 12:09:33
以及如何獲取屏幕尺寸? – Stupe 2012-08-07 12:10:50