I’m working on 2d game dev project.
It’s some kind of board game.
As background I have board game with path, that isn’t real circle, but some kind of wavy line.
Objects are moving across that path.
On touch event…I need to my player’s object get at that exact position, but they need to follow that path.
How to translate (draw) objects over some custom path?
I’ve came up with this simple solution, i’ve didnt payed attention to performance, ‘couse i need to keep it simple.
I’ve made class with Path and PathMeasure objects, mapPath is instance of that class.
I’ve took x and y coordinates from touchEvent and gave them as a parameters to my function.
I use simple function to calculate distance between two vectors, my pixels on the path, and vector I got from touchEvent.
Iterate until i get minimum of distance between them.
When i get x and y coordinate of my path, where i need to place my object, I simple translate object to that coordinates.
Its that simple, but its little dirty 🙂 Hope someone can use it someday, in hour of need. Cheers 😉