Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,737,406 Members 41,802 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
bmon3y
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 1
Join Date: Feb 2014
Default [Q] Creating a "dots" inspired game, need help with a touch concept.

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.
 
painlessDeath
Old
#2  
Junior Member
Thanks Meter 2
Posts: 13
Join Date: Feb 2013
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.

On ACTION_DOWN

create a Map<Rect, View> for all the dots, where Rect is the position of that view in the viewgroup,
Code:
Select Code
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.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes