Author Topic: Touch responsiveness  (Read 7827 times)

filippopotamus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Touch responsiveness
« on: October 01, 2012, 09:06:01 PM »
I am running into some issues with touch response on iOS. Here are the 2 issues I am having:

1) Button: I have some buttons that have UIButtonSound and UIButton scale that go off OnPress, and a UIButtonMessage that goes off OnClick. Very frequently, me and my testers tap on the button and you see it scale and hear the sound, but the message from UIButtonMessage is never sent. Very often we have to tap on the button 3-4 times for it to actually take effect

2) Scroll list: I have a UIGrid of buttons in my little store. You scroll up and down and it works great, you tap and the buttons work. Perfect. BUT, if my scroll is not too long (only scroll up or down a bit), when I release the finger it treats as a tap and it ends up pressing the button where my finger was. It is a VERY undesirable thing to have on my store.

Any thoughts on how to remediate these issues? Thank you so much in advance, NGUI is a lifesaver!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Touch responsiveness
« Reply #1 on: October 01, 2012, 11:46:32 PM »
I'm guessing #1 is because the touch is released away from the button rather than on its surface. There was a thread about it roughly a day before yesterday, with a fix... The same fix will be in the next version of NGUI when I release it.

As for #2 you will probably want to record the position in OnPress(true) and check the delta in OnClick() -- if it's within a certain threshold, proceed with the click logic.

filippopotamus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: Touch responsiveness
« Reply #2 on: October 16, 2012, 01:27:18 PM »
I see there is support for this (I don't know if it is new or not) but on UICamera I see Touch Drag/Click Thresholds. The problem I am running with it though is that the default clickNotifications are always set to Always. And for those to work I need those to be set to BasedOnDelta. What is the best way to default the clicks to BasedOnDelta? I don't think monitoring my touches to decide which one I want to be Always and which one should be BasedOnDelta is the optimal solution. Any ideas?

filippopotamus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: Touch responsiveness
« Reply #3 on: October 16, 2012, 02:06:43 PM »
Scratch that last one. Going through your code I see that you automatically set it to BasedOnDelta if it is being dragged. But I ran into this:

  1. float click  = isMouse ? mouseClickThreshold : Mathf.Max(touchClickThreshold, Screen.height * 0.1f);

and then

  1.  else if (currentTouch.clickNotification == ClickNotification.BasedOnDelta && click < mag)
  2.          {
  3.                // We've dragged far enough to cancel the click
  4.                currentTouch.clickNotification = ClickNotification.None;
  5.           }

Which is only going to happen if my drag is 10% of the height of the device or more? On the iPhone 5 it would have to be dragged 113 pixels or more for it to cancel the click. I changed it to this:

  1. float click  = isMouse ? mouseClickThreshold : touchClickThreshold;//Mathf.Max(touchClickThreshold, Screen.height * 0.1f);
  2.  

This seems to work. But I am afraid to change your code because my changes would disappear once there is a new update. Am I being completely derp about this? :P

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Touch responsiveness
« Reply #4 on: October 16, 2012, 03:22:57 PM »
I'm thinking of just eliminating that 0.1 altogether, or making it be exposed, and thus modifiable.

filippopotamus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: Touch responsiveness
« Reply #5 on: October 16, 2012, 03:33:17 PM »
I guess some people might benefit from it being exposed. I think just not having it and using the UICamera.touchClickThreshold should suffice. Unless there is some benefit having it that I am not seeing. For now I'll just ignore it. Thanks for the help. Awesome tool!

Cheers!

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Touch responsiveness
« Reply #6 on: October 17, 2012, 02:25:56 AM »
Quick fix for using dpi on mobile devices:

  1. //define this were you want, or you can use the exposed floats in UICamera
  2. //threshold in inches
  3. public const float DRAG_THRESHOLD = 0.08f; // ~ 0.2cm
  4.  
  5.  
  6. //the top of ProcessTouch in UICamera: line 920ish
  7. float drag   = Screen.dpi * DRAG_THRESHOLD; //use the same threshold for mouse and touch (use a different variable if you want to split them)
  8. float click  = Screen.dpi * DRAG_THRESHOLD; //use the same threshold for mouse and touch (use a different variable if you want to split them)
  9.  

Now the click and drag thresholds is based on realworld sizes rather than pixels.

Do note that if Screen.dpi doesn't work for your device, this will fail as it will then be 0, so I wrap it in my own code to do some calculations if Screen.dpi is bad.

If you want to manually set dpi, see http://members.ping.de/~sven/dpi.html

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Touch responsiveness
« Reply #7 on: December 17, 2014, 03:29:59 PM »
Sorry for the old bump, but we still have the issue with the buttons, sometimes you click on the button and does the TweenScale and play the sound, but doesn't go to the OnClick method.

I start changing the UICamera touch tresholds with no results.

Any help will be appreciated!  :-[

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Touch responsiveness
« Reply #8 on: December 17, 2014, 03:37:33 PM »
The touch may simply get released outside the button, thus invalidating the click.

Make the colliders bigger.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: Touch responsiveness
« Reply #9 on: December 17, 2014, 03:38:53 PM »
But the thresholds should work for this also or not?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Touch responsiveness
« Reply #10 on: December 17, 2014, 03:56:31 PM »
Nope.