(libgdx学习)Polling

官方文档部分解释

Each finger that goes down on the screen gets a so called pointer index. The first finger to go down gets the index 0, the next one gets the index 1 and so on. If a finger is lifted off the screen and touched down again, while other fingers are still on the screen, the finger will get the first free index. An example:

  1. first finger goes down -> 0
  2. second finger goes down -> 1
  3. third finger goes down -> 2
  4. second finger goes up -> 1 becomes free
  5. first finger goes up -> 0 becomes free, at this point only 2 is used
  6. another finger goes down -> 0, as it is the first free index
优先分配最小索引


一、初始化及常见的API


//		System.out.println("--------->isTouched(): " + Gdx.input.isTouched());//判断是否有手指点下去
//		System.out.println("--------->isTouched(0): " + Gdx.input.isTouched(0));//判断第一个手指是否已经点下去
//		System.out.println("--------->isTouched(1): " + Gdx.input.isTouched(1));
//		System.out.println("--------->isTouched(2): " + Gdx.input.isTouched(2));
//		System.out.println("--------->justTouched(): " + Gdx.input.justTouched());//判断手指是否刚刚点下去
		

System.out.println("-------->Gdx.input.getX(0): " + Gdx.input.getX(0) + ",Gdx.input.getY(0): " + Gdx.input.getY(0));


二、应用举例

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.graphics.GL10;

public class MyGame implements ApplicationListener {

	@Override
	public void create() {
		
	}

	@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);
		
		
//		System.out.println("--------->isTouched(): " + Gdx.input.isTouched());//判断是否有手指点下去
//		System.out.println("--------->isTouched(0): " + Gdx.input.isTouched(0));//判断第一个手指是否已经点下去
//		System.out.println("--------->isTouched(1): " + Gdx.input.isTouched(1));
//		System.out.println("--------->isTouched(2): " + Gdx.input.isTouched(2));
//		System.out.println("--------->justTouched(): " + Gdx.input.justTouched());//判断手指是否刚刚点下去
		
		if(Gdx.input.isTouched(0)){
			System.out.println("-------->Gdx.input.getX(0): " + Gdx.input.getX(0) + ",Gdx.input.getY(0): " + Gdx.input.getY(0));
		}
		
		if(Gdx.input.isTouched(1)){//isTouched(1)判断第一个手指是否已经点下去
			/**
			 * Gdx.input.getX(1): 获取第一个手指的x坐标
			 * Gdx.input.getY(1): 获取第一个手指的y坐标
			 */
			System.out.println("-------->Gdx.input.getX(1): " + Gdx.input.getX(1) + ",Gdx.input.getY(1): " + Gdx.input.getY(1));
		}
		
		if(Gdx.input.isTouched(2)){
			System.out.println("-------->Gdx.input.getX(2): " + Gdx.input.getX(2) + ",Gdx.input.getY(2): " + Gdx.input.getY(2));
		}
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

}


三、源码下载

http://download.youkuaiyun.com/detail/caihongshijie6/7041093


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值