次のコードを使用して、surfaceCreated() で背景画像を設定します。
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.untitled);
float heightScale = ((float)background.getHeight())/(float)this.getHeight();
float widthScale = (float)background.getWidth()/(float)this.getWidth();
float scale = heightScale > widthScale ? widthScale : heightScale;
int newWidth = Math.round((float)background.getWidth()/scale);
int newHeight = Math.round((float)background.getHeight()/scale);
scaled = Bitmap.createScaledBitmap(background, newWidth, newHeight, true);
保護されたビットマップでスケーリングされます。onDraw() 関数の間に、私はこれを持っています:
canvas.drawBitmap(scaled, 0, 0, null); // draw the background
これを使用すると、描画が20〜30ミリ秒遅くなります:
canvas.drawColor(Color.Black);
これを回避する方法はありますか?背景の onDraw 関数を高速化しますか? 背景を設定しないと、アプリが描画したスプライトをクリアしないことに気付きました。