在手机屏幕上移动 Pg

问题描述

嗨,我尝试只为 Android 制作视频游戏,但我不能使用 c 或其他环境。 我不明白如何使用路径来移动我的图像,因为路径插值器请求从 (0,0) 开始并在 (1,1) 中结束,但是如果我想在 (x,y) 中移动 al,我该怎么做? 我已经写了一部分 onTouchEvent,但我不明白文档。请帮助我并帮助所有人。

这是我的方法 @覆盖 public boolean onTouchEvent(MotionEvent event) {

    int action = event.getActionMasked();
    float newX = event.getX();
    float newY = event.getY();

    switch (action) {
        case (MotionEvent.ACTION_DOWN):
            Log.d(DEBUG_TAG,"Action was DOWN");
            Path path = new Path();
            path.moveto(newX,newY);
            PathInterpolator pathInterpolator = new PathInterpolator(path);
            

            ObjectAnimator animation = ObjectAnimator.ofFloat(PG,"translationX",100f);
            animation.setInterpolator(pathInterpolator);
            animation.start();

            break;
        case (MotionEvent.ACTION_MOVE):
            Log.d(DEBUG_TAG,"Action was MOVE");
            break;
        case (MotionEvent.ACTION_UP):
            Log.d(DEBUG_TAG,"Action was UP");
            break;
        case (MotionEvent.ACTION_CANCEL):
            Log.d(DEBUG_TAG,"Action was CANCEL");
            break;
        case (MotionEvent.ACTION_OUTSIDE):
            Log.d(DEBUG_TAG,"Movement occurred outside bounds " +
                    "of current screen element");
            break;
    }
    return true;
} 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)