官方文档部分解释
1)
The GestureListener
can
signal whether it consumed the event or wants it to be passed on to the next InputProcessor by returning either true or false respectively from its methods.
As with the events reported to a normal InputProcessor
,
the respective methods will be called right before the call to ApplicationListener.render()
on
the rendering thread.
The GestureDetector
also
has a second constructor that allows it to specify various parameters for gesture detection. Please refer to the Javadocs for
more information.
GestureDetector同样适用于inputprocessor对事件处理的的链式传递规则,因为GestureDetector实现了inputprocessor接口
二、应用举例
MyGestureDetector
package com.example.groupactiontest; import com.badlogic.gdx.input.GestureDetector.GestureListener; import com.badlogic.gdx.math.Vector2; public class MyGestureListener implements GestureListener { @Override public boolean fling(float arg0, float arg1, int arg2) {//fling和pan差不多 System.out.println("------->fling"); return false; } @Override public boolean longPress(float arg0, float arg1) {//长按 System.out.println("------->longPress"); return false; } @Override public boolean pan(float arg0, float arg1, float arg2, float arg3) { System.out.println("------->pan"); return false; } @Override public boolean pinch(Vector2 arg0, Vector2 arg1, Vector2 arg2, Vector2 arg3) {//pinch和zoom差不多 System.out.println("------->pinch"); return false; } @Override public boolean tap(float arg0, float arg1, int arg2, int arg3) {//tap和touchdown差不多 System.out.println("------->tap"); return false; } @Override public boolean touchDown(float arg0, float arg1, int arg2, int arg3) { System.out.println("gesturedetector------->touchDown"); return true; } @Override public boolean zoom(float arg0, float arg1) { System.out.println("------->zoom"); return false; } }
package com.example.groupactiontest; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Peripheral; import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.input.GestureDetector; public class MyGame implements ApplicationListener { InputProcessor inputProcessor; @Override public void create() { inputProcessor = new InputProcessor() { @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { // TODO Auto-generated method stub return false; } @Override public boolean touchDragged(int screenX, int screenY, int pointer) { // TODO Auto-generated method stub return false; } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { System.out.println("inputprocessor:--->towndown" ); return false; } @Override public boolean scrolled(int amount) { // TODO Auto-generated method stub return false; } @Override public boolean mouseMoved(int screenX, int screenY) { // TODO Auto-generated method stub return false; } @Override public boolean keyUp(int keycode) { // TODO Auto-generated method stub return false; } @Override public boolean keyTyped(char character) { // TODO Auto-generated method stub return false; } @Override public boolean keyDown(int keycode) { // TODO Auto-generated method stub return false; } }; //GestureDetector同样适用于inputprocessor的链式传递规则(因为GestureDetector就是实现了inputprocessor接口的) InputMultiplexer inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(new GestureDetector(new MyGestureListener())); inputMultiplexer.addProcessor(inputProcessor); Gdx.input.setInputProcessor(inputMultiplexer); } @Override public void dispose() { // TODO Auto-generated method stub } @Override public void pause() { // TODO Auto-generated method stub } @Override public void render() { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); } @Override public void resize(int arg0, int arg1) { // TODO Auto-generated method stub } @Override public void resume() { // TODO Auto-generated method stub } }
三、效果图
若GestureDetector中的touchDown的返回值为false,则logcat中的输出结果是
若GestureDetector中的touchDown的返回值为true,则logcat中的输出结果是
四、源码下载
http://download.csdn.net/detail/caihongshijie6/7041627
(libgdx学习)GestureDetector,布布扣,bubuko.com
原文:http://blog.csdn.net/hjd_love_zzt/article/details/21244299