[英]Libgdx get pressure of touch event
I am developing a pressure sensitive game on android. 我正在Android上开发压力感应游戏。 (Or with other words the game is finished) But know i want to start using a game engine and i decided to use Libgdx.
(或者换句话说,游戏结束了)但是知道我想开始使用游戏引擎,所以我决定使用Libgdx。 However the GestureDetector.GestureListener and the InputProcessor Interface do not provide the pressure parameter from the android internal MotionEvent.
但是,GestureDetector.GestureListener和InputProcessor接口不提供来自android内部MotionEvent的pressure参数。 I tried to manually set the Game as a View.OnTouchListener but that is interfering with the threading model ...
我试图将Game手动设置为View.OnTouchListener,但这会干扰线程模型...
any suggestions for a work around? 有什么建议可以解决吗?
There is only one option so far i know ie getPressure()
from MotionEvent
class. 有那么据我所知,即只有一个选项
getPressure()
从MotionEvent
类。 the function will give you the value between 0 to 1 in float. 该函数将为您提供浮点数介于0到1之间的值。 docs
文档
Note : Device without pressure sensor simulate pressure by the size of touch point. 注意:没有压力传感器的设备会根据接触点的大小来模拟压力。
More pressure means more area of screen covered by finger . 更大的压力意味着更多的屏幕被手指覆盖 。
setOnTouchListener
can give you MotionEvent
object from which you can get the pressure value like. setOnTouchListener
可以给你MotionEvent
对象,从中可以得到这样的压力值。
someView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float pressure = event.getPressure();
}
});
Here is part of my code for adding the pressure to a game object 这是我的代码的一部分,用于向游戏对象施加压力
final MyGdxGame game = new MyGdxGame();
View view = initializeForView(game, config);
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
getInput().onTouch(v, event);
game.setPressure(event.getPressure());
Log.v("log", "hooked " + event.getPressure());
return true;
}
});
The trick is that I have to call initializeForView
in order to overwrite the onTouchListener
and forward the MotionEvent
to the Input Handler of Libgdx
. 诀窍是,我要叫
initializeForView
以覆盖onTouchListener
和转发MotionEvent
到的输入处理程序Libgdx
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.