Android的触摸检测 [英] android detect touching
问题描述
我工作的一个简单的游戏。
当用户触摸屏幕,增加了一些变数。
虽然没有,什么也不做。
我使用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
andACTION_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
andACTION_UP
events (=If you need a hint, you might start by looking at:
这篇关于Android的触摸检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!