我一直在尝试开发这个游戏,用户必须点击图像上的某些点.我一直根据像素位置存储这些点.通过获取onTouch事件中的X和Y坐标,我可以轻松地按下像素.但是我面临的问题是每次都难以按下像素的确切位置(因此,为了测试目的,我在所有4个方向上设置了40 px的容差).那么有没有一种方法可以设置某种容差,可以从设置菜单进行调整,以便人们可以轻松地使用不同手指尺寸的人,并从不同的屏幕尺寸播放?我们非常感谢您提供任何帮助或建议
tolerance = 40
public boolean onTouchEvent(MotionEvent event) {
// MotionEvent object holds X-Y values
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int XCood = (int) event.getX();
int YCood = (int) event.getY();
int XMin = ActXCod[index] - tolerance,
XMax = ActXCod[index] + tolerance,
YMin = ActYCod[index] - tolerance,
YMax = ActYCod[index] + tolerance;
if (index < (limit - 1)) // loop to check number of images
{
if(XCood > XMin && XCood < XMax && YCood > YMin && YCood < …Run Code Online (Sandbox Code Playgroud)