Remove All Ads from XDA
Honor View 10

[Q] Creating a "dots" inspired game, need help with a touch concept.

1 posts
Thanks Meter: 0
By bmon3y, Junior Member on 28th February 2014, 12:49 AM
Post Reply Email Thread
I am trying to develop a game that uses touch between multiple objects. I need to detect when multiple items are touched on one swipe of the finger. The game is similar to "Dots" if you have ever played it. So I need to detect when a dot is pressed and then from there when the finger is dragged to detect the next dot that is touched. I need to keep this going until the finger is lifted. Using dispatchtouchevent and viewgroups is on the right track I think, but that is the furthest I have gotten.
9th March 2014, 07:49 AM |#2  
Junior Member
Thanks Meter: 22
When you are tracking a single touch movement, all the events would be sent to a single view.
So instead of tracking touch events for each Dots, you should track touch events for the common parent ViewGroup.

Lets say you have a frame layout with all the dots places inside.


create a Map<Rect, View> for all the dots, where Rect is the position of that view in the viewgroup,
Rect pos = new Rect(child.getLeft(), child.getTop(), child.getLeft() + child.getWidth(), child.getTop() + child.getHeight());
Essentially you need to create this map only once (and probably again after a relayout).
Then check which Dot was pressed using Rect.contains for each rect,

then on ACTION_MOVE,
Check if the same view was touched, and if not, again check for all the views to see if any other view was touched.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes