我正在尝试弄清楚如何使用我的onTouch方法的输入在画布视图上移动位图。到目前为止,我的位图只以45°的角度移动,直到我的位图的一个X或Y坐标与手指触摸相匹配。有人知道我如何改变X或Y坐标之一的速度,让它“飞”到手指所在的位置吗?感谢您的帮助:)
My 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();
}onTouch:
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;
}如果你还需要别的什么来回答我的问题,请不要犹豫,尽管开口!
发布于 2013-11-12 22:45:41
我在之前构建的一个应用程序中使用了这个教程。试着真正理解他在做什么,你就会找到答案。
http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/
https://stackoverflow.com/questions/19932134
复制相似问题