gpt4 book ai didi

java - Libgdx - 大约 2 人游戏。我希望每个玩家都可以用一根手指触摸自己的区域

转载 作者:行者123 更新时间:2023-11-30 06:49:05 26 4
gpt4 key购买 nike

我正在创建 2 名玩家的游戏,每个玩家都有自己的区域。我希望每个玩家都可以用一根手指触摸自己的区域。所以首先我将“达阵”功能限制为“2 个指针”。

public boolean touchDown(int screenX, int screenY, int pointer, int button){
if(pointer > 1){
return false;
}
Gdx.app.log("", "pointer: "+pointer);

return false;
}

但问题是,如果一名玩家用两根手指触摸自己的区域,另一名玩家将无法触摸自己的区域。我该如何解决这个问题?谢谢。

最佳答案

您不应该根据指针编号拒绝。

如果您想允许第一个指针在屏幕的每一侧向下,您可以执行以下操作(未经测试):

private int player1Pointer = -1, player2Pointer = -1;
private int player1X, player1Y, player2X, player2Y;

//...

public boolean touchDown(int screenX, int screenY, int pointer, int button){

// Assuming top and bottom halves of screen:
if (screenY > Gdx.graphics.getHeight() / 2){ // player 1 side
if (player1Pointer >= 0) // player 1 already touching somewhere
return false;
player1Pointer = pointer;
player1X = screenX;
player1Y = screenY;
} else { //player 2 side
if (player2Pointer >= 0) // player 2 already touching somewhere
return false;
player2Pointer = pointer;
player2X = screenX;
player2Y = screenY;
}
return true;
}

public boolean touchDragged (int screenX, int screenY, int pointer) {
if (pointer == player1Pointer){
player1X = screenX;
player1Y = screenY;
return true;
}
if (pointer == player2Pointer){
player2X = screenX;
player2Y = screenY;
return true;
}
return false;
}

public boolean touchUp (int screenX, int screenY, int pointer, int button) {
if (pointer == player1Pointer){
player1Pointer = -1;
return true;
}
if (pointer == player2Pointer){
player2Pointer = -1;
return true;
}
return false;
}

关于java - Libgdx - 大约 2 人游戏。我希望每个玩家都可以用一根手指触摸自己的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43154226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com