Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP bmon3y

28th February 2014, 12:49 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Feb 2014
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: 2
 
13 posts
Join Date:Joined: 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:
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
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes