I'm having some trouble getting an object to follow a path that is drawn with a touch event. The problem is more in the smoothness of which the object follows the path.
/* 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. */
I grab the coordinates as the user drags their finger across the screen using the historic methods so I d开发者_运维知识库on't miss any points.
The problem is the smoothness that the object moves along this path.
If you draw your path slow then the droid will move slowly across the screen ( because more x,y points are captured? ) But if you draw the line fast then the droid moves really fast.
I need the object to move at a consistent speed across the path.
I somehow need to regulate the spacing between the points added to the hashTable or the sample rate at which points are read in so its consistent and the object looks smooth following the path.
I've googled this one a good bit and i'm having some trouble finding anything. Any shove in the right direction would be appreciated.
Thanks so much!
Here I showed how to move and rotate an image along any path. Build a smooth path from your points. Then you can specify any number of points to make nice animation.
精彩评论