Saturday, October 5, 2013

Not So Fast Buddy

After posting my touch controls script I was fooling around with it and of course found a huge bug. If you're holding down one of the arrows, and then tap one of the colored buttons, the cube will stop moving. The culpit was the code that set the arrow flags false on touches received outside those flags. This was required to support the fairly standard use case of dragging a finger from one arrow to the other; the first arrow needed to flip off in that case.

The solution I went with was to do another layer of checking on any touch outide the rect we're currently looking at, and if this other touch is on a button, we can ignore it. This way we'll turn arrows off both if you drag a finger into the other arrow, and if you drag that finger out of the arrow area entirely. The only downside here is that a random tap, near the top of the screen for instance, will make both arrows false. But, I might reasonably ask, what were you doing tapping up there anyway, that's not where the controls are... the menu UI elements are already responding OK to touch, so hopefully this won't break those. I guess we'll find out. Anyway, the extra code is here:

bool OrphanTouch(Vector2 screenPos)

bool isOrphan = false;
 //don't count the other arrows for this
 (!greenButton.Contains(screenPos) &&
isOrphan = true;
return isOrphan;

No comments:

Post a Comment