我正在尝试为我的 android 游戏制作一个浮动操纵杆,但我无法这样做。这是我的 onTouch() 函数:
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
c = holder.lockCanvas();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
float x = event.getX();
float y = event.getY();
Log.d("joystick", " " + x + " " + y);
ondraw(c, x, y);
break;
case MotionEvent.ACTION_MOVE:
d = holder.lockCanvas();
float xdrag = event.getX();
float ydrag = event.getY();
Log.d("joystick move", " " + xdrag + " " + ydrag);
ondraw(d, xdrag, ydrag);
break;
}
return false;
}
由于某种原因,图像没有拖动。有人可以在这里告诉问题并帮助我吗?
我的抽签是:
protected void ondraw(Canvas c, float x, float y) {
c.drawColor(Color.BLACK);
c.drawBitmap(bmpback, x - (bmpback.getWidth() / 2),
y - (bmpback.getHeight() / 2), null);
c.drawBitmap(bmpfront, x - (bmpfront.getWidth() / 2),
y - (bmpfront.getHeight() / 2), null);
holder.unlockCanvasAndPost(c);
}