1
私はゲームで私のバックグラウンドを移動するためのガイドでコードを書き、それが働いているが、私の背景のサイズはオリジナルであると私はフルスクリーンでの私の移動の背景のサイズを作りたい、、)私を助けてください)フルスクリーンで背景を作る方法は?
コード:
public class Background extends SurfaceView implements
SurfaceHolder.Callback {
private Bitmap backGround;
public Background(Context context) {
super(context);
backGround = BitmapFactory.decodeResource(context.getResources(),
R.drawable.cold_planet);
setWillNotDraw(false);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
doDrawRunning(canvas);
invalidate();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
/**
* Draws current state of the game Canvas.
*/
private int mBGFarMoveX = 0;
private int mBGNearMoveX = 0;
private void doDrawRunning(Canvas canvas) {
// decrement the far background
mBGFarMoveX = mBGFarMoveX - 1;
// decrement the near background
mBGNearMoveX = mBGNearMoveX - 4;
// calculate the wrap factor for matching image draw
int newFarX = backGround.getWidth() - (-mBGFarMoveX);
// if we have scrolled all the way, reset to start
if (newFarX <= 0) {
mBGFarMoveX = 0;
// only need one draw
canvas.drawBitmap(backGround, mBGFarMoveX, 5000, null);
} else {
// need to draw original and wrap
canvas.drawBitmap(backGround, mBGFarMoveX, 0, null);
canvas.drawBitmap(backGround, newFarX, 0, null);
}
}
}
例:
ありがとうございますが、この部分を追加する必要がありますか? – En1q0d