Android的触摸检测 [英] android detect touching

查看:142
本文介绍了Android的触摸检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个简单的游戏。
当用户触摸屏幕,增加了一些变数。
虽然没有,什么也不做。
我使用surfaceView
onTouchEvent,但它不工作,因为它被称为一次。我如何可以完成这样的功能?

  @覆盖
公共布尔onTouchEvent(MotionEvent事件){
    vehicle.vel_y - = 0.2F;
    返回super.onTouchEvent(事件);
}


解决方案

阅读有关的传递给了onTouchEvent方法MotionEvent 秒。详细的,请看 ACTION_DOWN ACTION_UP 。当指针触摸屏,当它离开屏幕您应该收到移动事件。

除此之外,最有趣的部分是搞清楚如何记录 ACTION_DOWN ACTION_UP 事件之间的进展(=

如果你需要一个提示,你可以通过查看启动:


  

重复使用处理事件


I am working on a simple game. While user is touching the screen, increment some variable. While not, do nothing. I am Using surfaceView onTouchEvent, but it doesn't work because it is called only once. How can I accomplish such functionality?

@Override
public boolean onTouchEvent(MotionEvent event) {
    vehicle.vel_y -=0.2f;
    return super.onTouchEvent(event);
}

解决方案

Read about the MotionEvents that are passed to the onTouchEvent method. Specifically, look at ACTION_DOWN and ACTION_UP. You should receive motion events when a pointer touches the screen and when it leaves the screen.

Beyond that, the fun part is figuring out how to record progress between the ACTION_DOWN and ACTION_UP events (=

If you need a hint, you might start by looking at:

repeating events using handlers

这篇关于Android的触摸检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆