Multitouch drawing with surfaceview
In the past, I wrote an app that would draw lines with two touches. What I did was create two vectors, one for pointer ID 0 and one for Pointer ID 1 (thus anything else gets ignored). I would buffer up the points to draw in my onTouch method, and then draw the lines for the two separate lines in my surface draw method. I synched these parts of the code so that the UI thread and graphics thread wouldn't puke on each other. This worked fine.
Now what I want to do is the same, but with an unlimited number of touches. Since I have unlimited touches, and any random number of pointer IDs active on the screen, I won't be able to simply make vectors for multiple touches since I don't know how many touches there are.
What is a good way to buffer up multiple touches, with various pointer IDs so that I can draw them?开发者_高级运维
Perhaps there is an multitouch draw app out there that I can use as a reference?
Thanks,
One solution could be to use a map with integers as keys (the pointerIds) and paths as objects. On the touch side, start a path on TOUCH_DOWN, add it to the map, and then access it each time on the move. On the up, you can remove it from the map and "commit" it to a general purpose list of paths, independently from the initial pointerId (or you can store the original pointerId with the path).
So basically, while they are being drawn, keep the paths in a map indexed using the pointerId, and once they are finished, just keep them in a global list.
精彩评论