首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在画布视图上使用onTouch使用矢量移动位图

在画布视图上使用onTouch使用矢量移动位图
EN

Stack Overflow用户
提问于 2013-11-12 22:41:06
回答 1查看 557关注 0票数 0

我正在尝试弄清楚如何使用我的onTouch方法的输入在画布视图上移动位图。到目前为止,我的位图只以45°的角度移动,直到我的位图的一个X或Y坐标与手指触摸相匹配。有人知道我如何改变X或Y坐标之一的速度,让它“飞”到手指所在的位置吗?感谢您的帮助:)

My onDraw():

代码语言:javascript
复制
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:

代码语言:javascript
复制
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;
}

如果你还需要别的什么来回答我的问题,请不要犹豫,尽管开口!

EN

回答 1

Stack Overflow用户

发布于 2013-11-12 22:45:41

我在之前构建的一个应用程序中使用了这个教程。试着真正理解他在做什么,你就会找到答案。

http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19932134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档