如何让物体始终以最短的距离朝向/指向它已经跟随的方向
一个。我有一个对象。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您采用 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.