Android的libgdx刷卡左,用手势听众正确检测 [英] Android libgdx swipe left and right detection using gesture listener
问题描述
我已经显示的图像在与libgdx屏幕的中央。如果我刷卡左图像应的向左移动的,如果我向右滑动图像应的向右移动的。
随后刷卡向左应该向左移动图像。同样应该发生的权利。我用 GestureListener
。
它可以在一定程度上在这个意义上,如果我刷卡左留下第一张图像移动。但在那之后,如果我尝试刷右侧的图像还是向左移动。
让我怎么克服这libgdx ??
类MyGestureListener实现GestureListener {
@覆盖
公共布尔一扔(浮点为arg0,浮动ARG1,ARG2 INT){
// TODO自动生成方法存根
如果(arg0都大于0)
IX + = 20;
其他
//否则,如果(为arg0 * 100>九)
IX-= 20;
的System.out.println(你好...............+九);
返回true;
}
Gdx.input.setInputProcessor(新GestureDetector(0.0,0.0,0.0,5F,新MyGestureListener()));
batch.draw(splashTexture,IX,IY);
我曾经在这个环节的例子。 <一href="https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/GestureDetectorTest.java" rel="nofollow">https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/GestureDetectorTest.java.
@覆盖
公共布尔一扔(浮点velocityX,浮velocityY,INT按钮){
如果(Math.abs(velocityX)&GT; Math.abs(velocityY)){
如果(velocityX大于0){
IX + = 20; // x cordinate
}否则如果(velocityX℃,){
IX-= 20;
} 其他 {
// 没做什么。
}
}其他{
//忽略的输入,因为我们不关心向上/向下刷卡。
}
返回true;
}
I have displayed a image at the center of the screen with libgdx. If i swipe left the image should move left and if i swipe right image should move right.
Subsequent swipes to the left should move the image left. The same should happen for right. I used GestureListener
.
It works to some extent in the sense if i swipe left first image moves left. But after that if i try to swipe right the image still moves left.
So how do i overcome this in libgdx??
class MyGestureListener implements GestureListener {
@Override
public boolean fling(float arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
if(arg0>0)
iX += 20;
else
// else if(arg0*100>iX)
iX-=20;
System.out.println("Hello..............."+iX);
return true;
}
Gdx.input.setInputProcessor(new GestureDetector(0.0f, 0.0f,0.0f, 5f,new MyGestureListener()));
batch.draw(splashTexture, iX, iY);
I used the example in this link. https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/GestureDetectorTest.java.
@Override
public boolean fling(float velocityX, float velocityY, int button) {
if(Math.abs(velocityX)>Math.abs(velocityY)){
if(velocityX>0){
iX+=20;//x cordinate
}else if (velocityX<0){
iX-=20;
} else {
// Do nothing.
}
}else{
// Ignore the input, because we don't care about up/down swipes.
}
return true;
}
这篇关于Android的libgdx刷卡左,用手势听众正确检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!