【问题标题】:ClickListener enter/exit events not working properly LibgdxClickListener 进入/退出事件无法正常工作 Libgdx
【发布时间】:2017-06-24 11:00:28
【问题描述】:

我正在创建一个包含多个参与者的Table。该表还包含一个附加了 ClickListener 的图像。当其他演员被点击或点击时,我会绘制一个箭头,该箭头可以定位表格中的图像。我想知道箭头何时进入和退出表格中的图像。问题是输入事件并不总是触发,或者它仅从图像的一部分触发,或者一旦触发输入,就会触发退出。 知道有什么问题吗?

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();
        }

【问题讨论】:

    标签: libgdx scene2d clicklistener


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多