关于LibGdx的addListener [英] about LibGdx addListener

查看:609
本文介绍了关于LibGdx的addListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这个问题已经被问过,但似乎我有点不走运找到它。我的问题是我怎么启用按钮/演员的的addListener 在这个过程中间?在活动屏幕之间举个例子,资产加载屏幕上(让我们假设用户完成A阶段,加载画面加载资产B阶段),继续按钮只能启用(显示previously,但不启用)的所有资​​产后,被装入。如果我添加的addListener到渲染()部分,它会创建大量匿名inputListener的按本<一个href=\"http://stackoverflow.com/questions/22161809/libgdx-actor-touchhandling-issue/22164061#22164061\">post.不过,我不认为如果我把它放在显示()部分它会工作。我的问题是,我应该把这个的addListener 为了让演员可触但不创造那些匿名的 inputListener ?什么是使用它的正确方法?

I believe this question has been asked before, but it seems that I am a bit unlucky to find it. My question is how do I enabling a button/actor’s addListener in middle of the process? Take for example, on assets loading screen in between activity screen (let assume that user finished Stage A, the loading screen is to load assets for Stage B), the continue button can only be enabled (displayed previously, but not enable) after the all assets is loaded. If I add the addListener in to the render() section, it will create lots of anonymous inputListener as per this post. However, I don’t think it will work if I place it in show() section. My question is where should I place this addListener in order to make an actor touchable yet does not create those anonymous inputListener? And what is the proper way to use it?

推荐答案

我会建议创造,而不是 ClickListener InputListener ,并将其添加如常。里面的监听你检查装载完成。如果它这样做,你做你想要做什么都。如果没有返回,没有任何行动。

I would recommend to create a ClickListener instead of an InputListener and add it as usual. Inside of the Listener you check if the loading is done. If it's done you do what ever you want to do. If not you return without any action.

要举一个例子,如何给 ClickListener 添加到TEXT按钮应该已经做你的任务:

To give you an example how to add an ClickListener to a TextButton which should already do your task:

    TextButtonStyle style = new TextButtonStyle();
    style.font = new BitmapFont();
    style.font.setColor(Color.WHITE);

    continue= new TextButton("continue",
            style);

    continue.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
             if(manager.update()){ //returns true if the AssetManager is done in case you use an AssetManager
                  basegameclass.setScreen("menu"); //sets the menu screen
             }else{
             //not done do nothing or do something else like showing loading not done
             }
        }
    });

将其添加到不同的演员或按钮应该是simmelar。只是要小心,其中还增加了按键的舞台是 Inputprocessor ​​。所以一定要加入像这样 Gdx.input.setInputProcessor(阶段);

To add it to different actors or Buttons it should be simmelar. Just take care that the Stage where the Button is added also is the Inputprocessor. So make sure you added it like this Gdx.input.setInputProcessor(stage);

在这种情况下,我不认为,你需要一个整体 InputListener 简单地为这个小任务ClickListener。在 InputListener 为您提供了更广泛的,你不需要我认为方法。它是用来检测 touchups 达阵和幻灯片事件等等,你不需要一个按钮,我认为。也许对你拖动演员。

In this case i don't think, that you need a whole InputListener simply take the ClickListener for this small task. The InputListener gives you a wider range of methods which you dont need i think. It is used to detect touchups and touchdowns and slide events and much more which you dont need for a button i think. Maybe for actors that you drag around.

创建此内所有屏幕的构造。千万不要做这种事情渲染方法里面,因为它会创建一个新的侦听每一帧。 (每秒60张!)

这篇关于关于LibGdx的addListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆