iDevGames Forums
Force Touch Events? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Force Touch Events? (/thread-8605.html)



Force Touch Events? - Ropeburn - Feb 4, 2011 12:24 PM

I can successfully overload and print out the values from:
touchesBegan:
touchesEnded:
touchesMoved:

When none of the touches are moving, there are no events generated. Is there anyway to force an update or get a list of all touches even if the touches are not in motion. I would like to know where all the touches are on every update frame of my game.


RE: Force Touch Events? - ThemsAllTook - Feb 4, 2011 12:55 PM

It's advisable to keep your own list of active touches. Add to the list in -touchesBegan:, compare pointers to figure out which one(s) you're dealing with in -touchesMoved:, and remove from the list in -touchesEnded: and -touchesCancelled:. This is really a bare necessity of processing touch events; unless I'm mistaken, when -touchesMoved: called, only touches that actually moved are passed to it. If there are active touches that didn't move, they won't be in its list.


RE: Force Touch Events? - Ropeburn - Feb 4, 2011 01:13 PM

I'll have to try that, but there is problem.

if you push finger #1 down and hold it down (no motion), you'll get a begin touch event. Pressing finger #2 down goes not generate any event until finger #1 moves.

What I'd like to do is capture all the fingers that are down and I don't see how that is possible even if I starting tracking.


RE: Force Touch Events? - EvolPenguin - Feb 4, 2011 01:28 PM

That doesn't seem correct, it should generate another beganTouches event. Can you post your code for those functions (used the code tags to get it formatted nicely)?
Alex


RE: Force Touch Events? - Ropeburn - Feb 4, 2011 03:03 PM

Not sure what the code tags are, hope you dont mind. I've posted the three functions I'm using to capture the events. I believe these are standard implementations, but could be wrong. You can drop this into a iPad GLES project, watch the console and the following will happens.

Only the first finger down will generate a begin event.
Only the first finger will generate an end event.
No other finger will generate any event until the first finger moves.

I would love to get begin, motion and end events for any and all fingers. Seems odd that I can't.
Code:
//---------------------------------------------------------------------
// touchesBegan
//---------------------------------------------------------------------
- (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
{
NSSet *allTouches = [event allTouches];

  printf("Begin Touch: ");

  for (UITouch *touch in allTouches)
  {
    if (touch.phase == UITouchPhaseBegan)
    {
    CGPoint location  = [touch locationInView: self];
      
       printf("(%5.2f %5.2f), ",location.x,location.y);
    }
  }
  
  printf("\n");
}




//---------------------------------------------------------------------
// touchesMoved
//---------------------------------------------------------------------
- (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
{
NSSet *allTouches = [event allTouches];

  printf("Move Touch: ");

  for (UITouch *touch in allTouches)
  {
    if (touch.phase == UITouchPhaseMoved)
    {
    CGPoint location  = [touch locationInView: self];
      
       printf("(%5.2f %5.2f), ",location.x,location.y);
    }
  }
  
  printf("\n");
}


//---------------------------------------------------------------------
// touchesEnded
//---------------------------------------------------------------------
- (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
{
NSSet *allTouches = [event allTouches];

  printf("End Touch: ");

  for (UITouch *touch in allTouches)
  {
    if (touch.phase == UITouchPhaseEnded)
    {
    CGPoint location  = [touch locationInView: self];
      
       printf("(%5.2f %5.2f), ",location.x,location.y);
    }

  }
  
  printf("\n");
}



RE: Force Touch Events? - EvolPenguin - Feb 4, 2011 03:38 PM

I formatted your code using the correct tags. Please use them when posting code. When I get a chance I'll check out the code to see if I can figure out what's going on.
Alex


RE: Force Touch Events? - Ropeburn - Feb 4, 2011 03:51 PM

Thanks Alex.


RE: Force Touch Events? - reubert - Feb 4, 2011 06:08 PM

This sounds kind of familiar, I believe I have struck it before, but can't remember exactly what the issue was.

You have setMultipleTouchEnabled:YES on your view right?


RE: Force Touch Events? - Ropeburn - Feb 4, 2011 08:02 PM

Yes, the multi touch flag is set by default when you have XCode create a GLES project.


RE: Force Touch Events? - KittyMac - Feb 4, 2011 08:16 PM

(Feb 4, 2011 08:02 PM)Ropeburn Wrote:  Yes, the multi touch flag is set by default when you have XCode create a GLES project.

I dropped your code into the EAGLView.m of a new OpenGLES project and... it worked just fine.

Code:
[Session started at 2011-02-04 22:15:02 -0500.]
// SINGLE TOUCH
Begin Touch: (363.00 477.00),
Move Touch: (348.00 509.00),
Move Touch: (348.00 508.00),
End Touch: (348.00 508.00),
// TWO TOUCHES
Begin Touch: (291.00 512.00), (477.00 512.00),
Move Touch: (291.00 513.00), (477.00 511.00),
Move Touch: (288.00 523.00), (480.00 501.00),
Move Touch: (287.00 523.00), (481.00 501.00),
Move Touch: (287.00 522.00), (481.00 502.00),



RE: Force Touch Events? - Ropeburn - Feb 4, 2011 08:54 PM

Hmm, thats good news and what I would expect. However, this what I get when I drop it into a new project.

Begin Touch: (597.00 749.00), // finger #1 down
Move Touch: (596.00 747.00),
Move Touch: (597.00 747.00),
Move Touch: (598.00 747.00),
Move Touch: (598.00 748.00), // finger #2 down
Move Touch: (598.00 749.00),
Move Touch: (598.00 750.00),
Move Touch: (107.00 756.00), (599.00 750.00), // finger #1 moving
Move Touch: (107.00 775.00), (600.00 749.00),
Move Touch: (600.00 748.00),
Move Touch: (109.00 794.00), (601.00 748.00),
Move Touch: (107.00 810.00), (602.00 748.00),
Move Touch: (105.00 824.00), (603.00 748.00),
Move Touch: (99.00 856.00), (604.00 748.00),
Move Touch: (605.00 748.00),
Move Touch: (97.00 860.00), (606.00 748.00),
Move Touch: (96.00 860.00), (606.00 749.00),
Move Touch: (606.00 750.00),
Move Touch: (603.00 751.00),
End Touch: (603.00 751.00), // finger #1 off


RE: Force Touch Events? - Ropeburn - Feb 4, 2011 09:08 PM

Ok, I believe I have found the issue. I did go back once again and check to see if I had enabled multi touch, and I had not. It appears that it is not automatically set as I had thought. I am sorry for wasting everyones time. Thanks for the help.
T.
setMultipleTouchEnabled:YES


RE: Force Touch Events? - omarmaris - Feb 9, 2011 11:47 PM

setMultipleTouchEnabled:YES is your answer..

Kind Regards
Upps sorry You already found the answer Smile sorry to not to read whole replies...