Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a 2d tile based tactic game. I want the map to be slided around (because it's bigger than the screen) with FreeDrag (It's perfectly done, the map can moved around, that's not the problem).

And then, I want to display the character's actions, everytime it's tapped.

The problem then appeared. Everytime I want to FreeDrag the map, the Tap trigger always fired first before the FreeDrag one. Is there any way to differ the map sliding than the character tapping? Below is my code.

while (TouchPanel.IsGestureAvailable)
{
    GestureSample gesture = TouchPanel.ReadGesture();
    switch (gesture.GestureType)
    {
        case GestureType.FreeDrag:
            {
                //a
            } break;
        case GestureType.Tap:
            {
                //b
            } break;
    }
}

Every time I first want to free drag (at the first touch), it always goes to "b" first (see commented line above), and then to "a" rather than immediately goes to "a".

I've tried flick, but it seems the movement produced by flick is too fast, so freedrag fits the most.

Is there any way or workaround to perform FreeDrag (or similar) without firing the Tap trigger?

Thanks in advance.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

To be honest I've never used the gesture API so my answer might be wrong. However, I think I know how to solve your problem.

The idea is to perform action B only if action A has not already occurred and the only way to know this is to somehow detect when the user has released their finger. Since their is no Release gesture type you might be able to craft your own like this:

bool isTapped = false;  
bool isDragged = false;

while (TouchPanel.IsGestureAvailable)
{
    GestureSample gesture = TouchPanel.ReadGesture();
    switch (gesture.GestureType)
    {
    case GestureType.FreeDrag:
        {               
           isDragged = true;
        } break;
    case GestureType.Tap:
        {
           isTapped = true;
        } break;
    }
}

if(isTapped && !isDragged)
{
    // b
}
else if(isDragged)  
{
    // a
}

You might also need to use some tolerance checking on the Delta values to see if the user has actually dragged a significant distance. Not sure.

That said, it does seem odd that the API behaves this way, it could it be a bug in MonoGame. It might be worth bringing this up on their forums and/or checking it against the behavior of XNA.

share|improve this answer
    
It works, but somehow, the freedrag performed very slow compared to when it is in the switch case –  Moses Aprico Jul 2 '13 at 8:10
    
Any idea how to fix that? –  Moses Aprico Jul 2 '13 at 16:28
    
Sorry, it seems that I pressed on a area not quick enough to freedrag. It's done well now if there is no delay between "tap" and drag to freedrag –  Moses Aprico Jul 5 '13 at 1:38
add comment

Sorry, it seems that I pressed on a area not quick enough to freedrag. It's done well now if there is no delay between "tap" and drag to freedrag

share|improve this answer
    
This should be a comment not an answer. Delete it if you can and please accept my answer if it's correct. Thanks. –  craftworkgames Jul 3 '13 at 21:46
    
no problem, it's not wrong anyway, just not perfect enough –  Moses Aprico Jul 5 '13 at 1:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.