【发布时间】: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 或 读取点的采样率使其一致并且对象看起来很平滑 跟随路径。
我已经用谷歌搜索了这个,但我很难找到任何东西。 任何朝着正确方向的推动都会受到赞赏。
非常感谢!
【问题讨论】: