我创造了2个玩家游戏,每个玩家都拥有自己的区域。我希望每个玩家都可以用一根手指触摸自己的区域。所以首先我在“触地”功能中限制为“2指针”。
stopUpdateLocation
但问题是如果一个玩家用他的2个手指触摸他自己的区域,另一个玩家将无法触及他自己的区域。我该如何解决这个问题?谢谢。
答案 0 :(得分:1)
你不应该根据指针编号拒绝。
如果你想让屏幕两侧的第一个指针向下,你可以这样做(未经测试):
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;
}
答案 1 :(得分:0)
你做不到。简单地假设球员公平,只触摸他们自己的区域。根据点击的区域处理点击次数,然后将操作分配给相应的玩家编号。
如果您需要区域内的指针索引,只需根据区域将指针编号分配给播放器1或2.在指针被触摸时删除分配。所以你现在总是在当前时刻将哪个指针编号分配给哪个玩家。
假设指针0是玩家1而指针1是玩家2则不起作用。