LIBGDX输入isTouched()

时间:2014-07-16 12:14:06

标签: java android eclipse libgdx

任何人都可以告诉我为什么我的播放器不会移动。它开始移动直到player.dat被保存,然后它只是轻微一点并返回到原始位置

public class Player implements Serializable, InputProcessor{

private static final long serialVersionUID = 1L;
Vector2 position, touchPosition;
String textureLoc;

public Player(Vector2 position, String textureLoc){
    this.position = position;
    }

public void update(){

    position = new Vector2(0,0);
    Vector2 touchPosition = new Vector2(0,0);


    if (Gdx.input.isTouched()){
        touchPosition.set(Gdx.input.getX(), Gdx.input.getY());

    }
    if(touchPosition.x > position.x){
        position.x += 2f;}

     if (touchPosition.x < position.x){
            position.x -= 2f;}

    if(touchPosition.y > position.y){
        position.y += 2f;}

     if (touchPosition.y < position.y){
            position.y -= 2f; 
    }

}

这是在Player类下。请帮忙。我被困了2天!

1 个答案:

答案 0 :(得分:2)

将其移至构造函数:

position = new Vector2(0,0);

如果您的update中有此行,则每次都会重置position

ps:你的私人和全球touchPosition也可能遇到麻烦