Little touch

There are several games that have small sprite art and can be moved by touch. If the sprite is larger, the touch is fine. And we can use a function CGRectContainsPoint

to validate the sprite. But when the sprite is quite small, this function doesn't look good. Is there any other way to handle the problem?

+2


a source to share


2 answers


I wrote about an approach you can use to mitigate the "fat finger" problem described in @FrustratedWithFormsDesigner:
http://codecube.net/2010/03/approximating-touch-points/

... what if you compare users' touch points to a position object and just select the closest one (no matter if it's 35 or 36 pixels)?



The post is written in C # for a Windows Phone, but the concept should apply. Basically, compare the distance between the touch user interface and objects on the screen. Make the touch pad the closest in distance, and you avoid the problems of hard-coded squares with which to detect touches.

+1


a source


You can enable touch in the area around the sprite. for example, if the touch is within 10 pixels of the sprite, treat it as if it were touching the sprite.

One way to do this is to expand the sprite rect before calling CGRectContainsPoint

. The following code will expand the rectangle by 10 for x and y:



CGRect expanded = CGRectInset(spriteRect, -10.0, -10.0);

      

Another way to do this is to create a rectangle around the touch and use CGRectIntersectsRect

it to check if the touch rect touches the sprite.

0


a source







All Articles