1
我正在創建一個包含多個參與者的Table
。該表還包含一個附帶ClickListener的圖像。從其他演員中,當他們被點擊或點擊時,我會繪製一個箭頭,該箭頭可以從表格中定位圖像。我想知道什麼時候箭頭進入並退出表格中的圖像。問題在於enter事件並不總是觸發,或者僅從圖像的一部分觸發,或者只要觸發輸入就會觸發exit。 任何想法可能是錯誤的?ClickListener進入/退出事件無法正常工作Libgdx
oponentHand = new Table();
for (int i = 0; i < 4; i++) {
oponentHand.add().width(game.developingWidth/(11.5f)).height(game.developingHeight/(5.5f)).padLeft(5)
.expand();
}
Texture oponentTexture = new Texture(Gdx.files.internal("data/mihai.jpg"));
Table tempTable = new Table();
oponentPortrait = new Image(oponentTexture);
oponentLife = new Label("Life", textsStyle);
tempTable.add(oponentLife).row();
oponentPortrait.setTouchable(Touchable.enabled);
tempTable.add(oponentPortrait).expand().fill();
oponentPortrait.addListener(new ClickListener() {
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
super.enter(event, x, y, pointer, fromActor);
isOnTarget = true;
targetedCardType = "enemyHero";
System.out.println("Entering enemy hero");
}
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
super.exit(event, y, y, pointer, toActor);
if (pointer == -1) {
isOnTarget = false;
System.out.println("Exiting enemy hero");
}
}
});
Texture oponentPowerTexture1 = new Texture(Gdx.files.internal("data/powSword.png"));
Texture oponentPowerTexture2 = new Texture(Gdx.files.internal("data/powShield.png"));
Image firstOponentPower = new Image(oponentPowerTexture1);
Image secondOponentPower = new Image(oponentPowerTexture2);
oponentHand.add(firstOponentPower).width(game.developingWidth/(11.5f)).height(game.developingHeight/(6))
.padLeft(5);
oponentHand.add(tempTable).width(game.developingWidth/(11.5f)).height(game.developingHeight/(6)).fill().padLeft(5);
oponentHand.add(secondOponentPower).width(game.developingWidth/(11.5f)).height(game.developingHeight/(6))
.padLeft(5);
for (int i = 0; i < 4; i++) {
oponentHand.add().width(game.developingWidth/(11.5f)).height(game.developingHeight/(6)).padLeft(5)
.expand();
}