@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mSurfaceWidth = width;
mSurfaceHeight = height;
mBallX = width / 2;
mBallY = height/(1.1f);
mVX = 0;
mVY = 0;
}
private void drawCanvas() {
Canvas c = mHolder.lockCanvas();
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
c.drawCircle(mBallX, mBallY, RADIUS, paint);
mHolder.unlockCanvasAndPost(c);
}
我想更改paint
中的c.drawCircle()
以使用我的图像。
我应该写什么代码?
答案 0 :(得分:0)
尝试
private void drawCanvas() {
Canvas c = mHolder.lockCanvas();
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.imagenamefromdrawableRes);
c.drawBitmap(bmp, mBallX, mBallY - RADIUS, null);
//c.drawCircle(mBallX, mBallY, RADIUS, paint);
mHolder.unlockCanvasAndPost(c);
}