首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阶段不会更改为其他阶段

阶段不会更改为其他阶段
EN

Stack Overflow用户
提问于 2018-02-26 16:09:34
回答 1查看 46关注 0票数 1

我在我的程序中有两个阶段,分别命名为" stagemain“和" stage”和游戏屏幕,第一个stage game出现,我点击“新游戏”,然后游戏开始。角色死了,舞台就来了。在第二阶段中,有一个homebutton图像。我添加了clickListener,所以它指向第一个屏幕(Stagemain)…但我遇到了一个问题。当我点击Home键时,第一个屏幕(Stage again )即将到来,而我首先点击按钮的第二个屏幕(Stage)突然再次出现。我点击Home键,stagemain出现了大约0.5秒,然后它又回到了stagemain。我试图解释我的问题发生了什么,我希望我能成功。谢谢

这是homebutton图像的clickListener代码。在gameState = 0的情况下,stagemain出现...当gameState = 2时,阶段到来了。在addListener代码中,我编写了stagemain的首选项。

代码语言:javascript
复制
 Texture homeButtonTexture = new Texture(Gdx.files.internal("homebutton5.png"));
    Image homeButtonImage = new Image(homeButtonTexture);
    homeButtonImage.setPosition(4*Gdx.graphics.getWidth()/10,Gdx.graphics.getHeight()/4+Gdx.graphics.getHeight()/22);
    homeButtonImage.setSize(Gdx.graphics.getWidth()/12,Gdx.graphics.getHeight()/10);

    homeButtonImage.addListener(new ClickListener(){
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button){
            if(gameState == 2){
                gameState = 0;
                birdY = 2 * Gdx.graphics.getHeight() / 3;   // Oyunu tekrar başlatırsak kuşun yerini ayarlıyor

                Gdx.input.setInputProcessor(stagemain);

                Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
                Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                stagemain.act(Gdx.graphics.getDeltaTime());

                stagemain.getBatch().begin();                                                                                    // stagemain nin background u ayarlama
                stagemain.getBatch().draw(background,0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());               // stagemain nin background u ayarlama
                stagemain.getBatch().draw(bird, birdX, birdY, Gdx.graphics.getWidth()/15, Gdx.graphics.getHeight()/10);
                stagemain.getBatch().end();                                                                                     // stagemain nin background u ayarlama
                stagemain.draw();
            }
            return true;
        }
    });
    stage.addActor(homeButtonImage);
EN

回答 1

Stack Overflow用户

发布于 2018-02-27 03:08:45

侦听器中的代码在点击按钮时执行一次,而不是像render方法中那样连续执行。在监听器内部绘制任何东西都没有意义,只是为了改变状态。您的渲染循环应该做出反应,并根据游戏状态绘制相应的屏幕。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48983980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档