我试图弄清楚如何使用我的 onTouch 方法的输入将位图移动到画布视图上。到目前为止,我的位图仅以 45° 角移动,直到我的位图的一个 X 或 Y 坐标与手指触摸匹配。有谁知道我如何改变 X 或 Y 坐标之一的速度,使其“飞”到手指所在的位置?谢谢你的帮助 :)
我的 onDraw():
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawBitmap(BackScaled,0,0,null);
canvas.drawBitmap(bobScale,meX-bobScale.getWidth(),meY - bobScale.getHeight(),null);
canvas.drawBitmap(grunScale,700,10,null);
if(touched == 1 && meX<= pressX && fliegen == 0){
meX = meX+ (width /300);
}
if(touched == 1 && meX >=pressX &&fliegen == 0){
meX = meX- (width / 300);
}
if(meX >= width -(width/6)){
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawText("The door is closed", 600, 350, paint);
}
if(pressX >= 700 && pressX < 800 && pressY >= 10 && pressY <= 110){
fliegen = 1;
}
if(meX<= pressX && meY >= pressY && fliegen == 1 &&touched ==1){
meX = meX+4;
meY = meY-4;
}
if(meX>= pressX && meY <= pressY && fliegen == 1 &&touched ==1){
meX = meX-4;
meY = meY+4;
}
if(meX >= pressX && meY >=pressY && fliegen == 1 && touched == 1){
}
invalidate();
}
触摸:
public boolean onTouch(View v, MotionEvent me) {
if (me.getAction() == MotionEvent.ACTION_DOWN){
touched = 1;
pressX = (int)me.getX();
pressY = (int)me.getY();
}
if(me.getAction()== MotionEvent.ACTION_MOVE);{
touched = 1;
pressX = (int)me.getX();
pressY = (int)me.getY();
}
if(me.getAction() == MotionEvent.ACTION_UP){
touched = 0;
}
return true;
}
如果您需要其他任何东西来回答我的问题,请不要犹豫!