官方文档部分解释
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:
- first finger goes down -> 0
- second finger goes down -> 1
- third finger goes down -> 2
- second finger goes up -> 1 becomes free
- first finger goes up -> 0 becomes free, at this point only 2 is used
- 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