ClickListener输入/退出事件无法正常工作Libgdx

ClickListener输入/退出事件无法正常工作Libgdx,libgdx,scene2d,clicklistener,Libgdx,Scene2d,Clicklistener,我正在创建一个包含多个参与者的表。该表还包含一个附加了ClickListener的图像。我从其他演员那里画了一个箭头,当他们被点击或点击时,这个箭头可以指向桌子上的图像。我想知道箭头何时进入和退出表中的图像。问题是enter事件并不总是被触发,或者它只从图像的一部分触发,或者一旦enter被触发,exit就会被触发。 你知道会出什么问题吗 oponentHand = new Table(); for (int i = 0; i < 4; i++) {

我正在创建一个包含多个参与者的
。该表还包含一个附加了ClickListener的图像。我从其他演员那里画了一个箭头,当他们被点击或点击时,这个箭头可以指向桌子上的图像。我想知道箭头何时进入和退出表中的图像。问题是enter事件并不总是被触发,或者它只从图像的一部分触发,或者一旦enter被触发,exit就会被触发。 你知道会出什么问题吗

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();
        }
oponthand=newtable();
对于(int i=0;i<4;i++){
oponthand.add().width(game.developingWidth/(11.5f)).height(game.developingHeight/(5.5f)).padLeft(5)
.expand();
}
纹理opontexture=新纹理(Gdx.files.internal(“data/mihai.jpg”);
Table tentable=新表();
opontrapital=新图像(opontexture);
oponentLife=新标签(“Life”,textsStyle);
attreable.add(oponentLife.row();
opontrait.setTouchable(Touchable.enabled);
detritable.add(opontrapital.expand().fill();
oponteractive.addListener(新建ClickListener(){
public void enter(InputEvent事件、浮点x、浮点y、int指针、Actor fromActor){
super.enter(事件、x、y、指针、fromActor);
isOnTarget=true;
targetedCardType=“enemyHero”;
System.out.println(“进入敌人英雄”);
}
公共无效退出(InputEvent事件、浮点x、浮点y、int指针、Actor toActor){
super.exit(事件,y,y,指针,toActor);
如果(指针==-1){
isOnTarget=false;
System.out.println(“退出敌人英雄”);
}
}
});
纹理opontPowerTexture1=新纹理(Gdx.files.internal(“data/powswire.png”);
纹理opontPowerTexture2=新纹理(Gdx.files.internal(“data/powShield.png”);
Image firstopontpower=新图像(opontpowertexture1);
Image secondoponetpower=新图像(oponetpowertexture2);
oponentHand.add(firstOponentPower).宽度(game.developingWidth/(11.5f)).高度(game.developingHeight/(6))
.左耳(5);
oponthand.add(诱惑).宽度(game.developingWidth/(11.5f)).高度(game.developingHeight/(6)).fill().左键(5);
oponentHand.add(secondOponentPower).宽度(game.developingWidth/(11.5f)).高度(game.developingHeight/(6))
.左耳(5);
对于(int i=0;i<4;i++){
oponthand.add().width(game.developingWidth/(11.5f)).height(game.developingHeight/(6)).padLeft(5)
.expand();
}

我发现了导致进入/退出事件未触发的问题。我在游戏后期添加了另一个演员到舞台上,碰巧它被添加到了我试图验证进入/退出事件的图像的顶部。我用
Action
在舞台上加入演员,然后淡入淡出,所以演员只在很短的时间内可见。问题是我从来没有把它从舞台上移开,因为淡出只会改变演员的阿尔法,所以它不允许下面的图像获得事件。我通过使用
操作将其淡出舞台后将其从舞台上移除来解决此问题。removeActor()
我发现了导致进入/退出事件无法触发的问题。我在游戏后期添加了另一个演员到舞台上,碰巧它被添加到了我试图验证进入/退出事件的图像的顶部。我用
Action
在舞台上加入演员,然后淡入淡出,所以演员只在很短的时间内可见。问题是我从来没有把它从舞台上移开,因为淡出只会改变演员的阿尔法,所以它不允许下面的图像获得事件。我通过使用
Actions.removeActor()
将其淡出舞台,然后将其从舞台上移除,从而解决了这个问题