如何让物体始终以最短的距离朝向/指向它已经跟随的方向

发布于 2025-01-06 19:33:05 字数 1542 浏览 2 评论 0原文

一个。我有一个对象。 b.当用户触摸屏幕时,它将缓动/补间到用户触摸坐标。 c.如果用户拖动手指,则对象将简单地通过运动事件 ACTION_MOVE 的输入数据所形成的路径来遵循该路径。

我该如何做到这一点,以便对象与用户触摸坐标的距离最短,而不是遵循他们创建的确切路径?

最终,该对象应该赶上用户的触摸坐标。

public Scene onLoadScene() {
    this.getEngine().registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

    final int x = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
    final int y = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
    final Sprite face = new Sprite(x, y, this.mFaceTextureRegion);
    scene.registerTouchArea(face);
    scene.attachChild(face);
    //face.setPosition(134, 200);
    //face.registerEntityModifier(new MoveModifier(500, x, 100, y, 200, EaseQuadIn.getInstance())); 

    scene.setOnSceneTouchListener(new IOnSceneTouchListener() {

        @Override
        public boolean onSceneTouchEvent(Scene pScene,TouchEvent pSceneTouchEvent) {
            int facePosX = (int) (pSceneTouchEvent.getX() - face.getWidth() / 2);
            int facePosY = (int) (pSceneTouchEvent.getY() - face.getHeight() / 2);

            if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_MOVE)
            {
                face.registerEntityModifier(new MoveModifier(1, face.getX(), facePosX,face.getY(), facePosY, EaseQuadIn.getInstance()));                
               }
            return true;            
            }
    });


    scene.setTouchAreaBindingEnabled(true);
    return scene;
}

a. I have an object.
b. when the user touches the screen it will ease/tween to the users touch coordinate.
c. if the user drags their finger then the object will follow that path simply by traversing the path made by the input data from the motion event ACTION_MOVE.

how do i make it so that the object takes the shortest distance to the users touch coordinates instead of following the exact path that they create?

Eventually, the object should catch up to the users touch coordinate.

public Scene onLoadScene() {
    this.getEngine().registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

    final int x = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
    final int y = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
    final Sprite face = new Sprite(x, y, this.mFaceTextureRegion);
    scene.registerTouchArea(face);
    scene.attachChild(face);
    //face.setPosition(134, 200);
    //face.registerEntityModifier(new MoveModifier(500, x, 100, y, 200, EaseQuadIn.getInstance())); 

    scene.setOnSceneTouchListener(new IOnSceneTouchListener() {

        @Override
        public boolean onSceneTouchEvent(Scene pScene,TouchEvent pSceneTouchEvent) {
            int facePosX = (int) (pSceneTouchEvent.getX() - face.getWidth() / 2);
            int facePosY = (int) (pSceneTouchEvent.getY() - face.getHeight() / 2);

            if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_MOVE)
            {
                face.registerEntityModifier(new MoveModifier(1, face.getX(), facePosX,face.getY(), facePosY, EaseQuadIn.getInstance()));                
               }
            return true;            
            }
    });


    scene.setTouchAreaBindingEnabled(true);
    return scene;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2025-01-13 19:33:05

我建议您采用 MotionEvent.ACTION_DOWN 和 MotionEvent.ACTION_UP,并获取开始和结束坐标,并相应地移动对象。

因此,您的起点将位于 ACTION_DOWN,终点将位于 ACTION_UP。

I would suggest you to take MotionEvent.ACTION_DOWN and MotionEvent.ACTION_UP, and get start and end co-ordinates, and move object accordingly.

So your start point would be on ACTION_DOWN and End Pont be on ACTION_UP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文