【问题标题】:How to get an object to follow a path如何让对象跟随路径
【发布时间】:2010-12-20 05:45:56
【问题描述】:

我在让对象遵循通过触摸事件绘制的路径时遇到了一些问题。 问题更多在于对象遵循路径的平滑度。

/* the ACTION_MOVE code */
Hashtable<String, Integer> ht = new Hashtable<String, Integer>();
for (int h = 0; h < historySize; h++) {
  for (int p = 0; p < pointerCount; p++) {
      int newX = (int) event.getHistoricalX(p, h);
      int newY = (int) event.getHistoricalY(p, h);
      ht.put("x", newX);
      ht.put("y", newY);
      droid.path.add(ht);
}

droid.p.lineTo(x, y);
}
/* There's a game loop that calls a move() method on this droid object.  In move I read the path list
   and see the next coordinate to move the object to. */

当用户在屏幕上拖动手指时,我使用 历史方法,所以我不会错过任何要点。

问题在于对象沿着这条路径移动的平滑度。

如果您缓慢绘制路径,那么机器人将在屏幕上缓慢移动 (因为更多的 x,y 点被捕获?) 但如果你画得很快,那么机器人移动得很快。

我需要对象在路径上以一致的速度移动。

我需要调节添加到 hashTable 或 读取点的采样率使其一致并且对象看起来很平滑 跟随路径。

我已经用谷歌搜索了这个,但我很难找到任何东西。 任何朝着正确方向的推动都会受到赞赏。

非常感谢!

【问题讨论】:

    标签: java android path


    【解决方案1】:

    Here 我展示了如何沿任意路径移动和旋转图像。根据您的观点构建a smooth path。然后你可以指定任意数量的点来制作漂亮的动画。

    【讨论】:

    • 我已经有一段时间没有从事这个项目了,但是非常感谢您的发帖。我只是想再次将其重新启动,所以我会试一试。
    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多