首页 > 其他 > 详细

(libgdx学习)GestureDetector

时间:2014-03-15 03:29:01      阅读:491      评论:0      收藏:0      [点我收藏+]

官方文档部分解释

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;
	}

}

MyGame

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中的输出结果是

bubuko.com,布布扣


若GestureDetector中的touchDown的返回值为true,则logcat中的输出结果是

bubuko.com,布布扣

四、源码下载

http://download.csdn.net/detail/caihongshijie6/7041627



(libgdx学习)GestureDetector,布布扣,bubuko.com

(libgdx学习)GestureDetector

原文:http://blog.csdn.net/hjd_love_zzt/article/details/21244299

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!