Libgdx结束级别无法正常工作

时间:2016-06-22 15:54:53

标签: java android libgdx

在我的游戏中,孩子正在收集水果,但是如果他在收集所需的点之前击中岩石3次或时间到了,孩子将跳到屏幕的一半然后跌倒并开始失败音乐然后移动到游戏在屏幕上,但我有两个问题:

  1. 当时间到了,男孩跳到最前面并继续.png而不是screen失败是缓慢且波涛汹涌。
  2. 当孩子击中岩石3次时,音乐开始失败并跳到屏幕中心并从bottom and the music跌落出来,这非常好然后去屏幕游戏,但是当我从screen from bottom返回播放屏幕的音乐不起作用: 这是代码:

    game over screen,

    这是gameover屏幕的代码:

    public boolean Rockhit()
        {
            if(Rocks.isRock) {
                rocknum--;
                Hud.collectorLives(rocknum);
                Rocks.isRock=false;
    
                if (rocknum == 0)
                    return true;
                else
                    return false;
    
            }
            else
                Hud.collectorLives(rocknum);
            return false;
        }
     public State getState()
        {
            //Gdx.app.log(Float.toString(b2body.getLinearVelocity().x),"hi");
            if ((Hud.getTime()==0&& Hud.getScore()<(level*30)+50)) {
                Fruits.manager.get("music/Backmusic.ogg", Music.class).stop();
                collectoIsDead=true;
                Filter filter = new Filter();
                filter.maskBits = Fruits.NOTHING_BIT;
                for (Fixture fixture : b2body.getFixtureList())
                    fixture.setFilterData(filter);
                b2body.applyLinearImpulse(new Vector2(0, 5f), b2body.getWorldCenter(), true);
                //b2body.applyLinearImpulse(new Vector2(0,-2.5f), b2body.getWorldCenter(), true);
                Fruits.manager.get("music/fail.mp3", Sound.class).play();
    
                return State.DEAD;
            }
            if ( Rockhit()) {
                Fruits.manager.get("music/Backmusic.ogg", Music.class).stop();
                collectoIsDead=true;
                Filter filter = new Filter();
                filter.maskBits = Fruits.NOTHING_BIT;
                for (Fixture fixture : b2body.getFixtureList())
                    fixture.setFilterData(filter);
                b2body.applyLinearImpulse(new Vector2(0, 5f), b2body.getWorldCenter(), true);
                //b2body.applyLinearImpulse(new Vector2(0,-2.5f), b2body.getWorldCenter(), true);
                Fruits.manager.get("music/fail.mp3", Sound.class).play();
    
                return State.DEAD;
            }
            if((Hud.getTime()==0&& Hud.getScore()>=(level*30)+50)|| (Hud.getScore()>=(level*30)+50)) {
                Fruits.manager.get("music/Backmusic.ogg", Music.class).stop();
                Fruits.manager.get("music/cheering.mp3", Sound.class).play();
                return State.SUCCESS;
            }
    

    这里我在播放屏幕中处理孩子的状态:

    public class GameOverScreen implements Screen {
        private Viewport viewport;
        private Stage stage;
        private Fruits game;
        private float level;
    
        public GameOverScreen(Fruits game,float level)
        {
            this.level=level;
            this.game=game;
            viewport=new FitViewport(Fruits.V_WIDTH,Fruits.V_HIEGT,new OrthographicCamera());
            stage=new Stage(viewport,((Fruits) game).batch);
            Label.LabelStyle font = new Label.LabelStyle(new BitmapFont(), Color.WHITE);
            Table table=new Table();
            table.center();
            table.setFillParent(true);//the table will take all the stage
    
            Label gameOverLabel = new Label("Game Over",font);
            Label playAgainLabel = new Label("Click Here",font);
            table.add(gameOverLabel).expandX();
            table.row();
            table.add(playAgainLabel).expandX().padTop(10f);// make it bellow Game over text by 10 pixels
            stage.addActor(table);
    
        }
    
    
        @Override
        public void render(float delta) {
            if(Gdx.input.isTouched()) {
                game.setScreen(new Worlds(game,level));
                dispose();
            }
            Gdx.gl.glClearColor(0,0,0,1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            stage.draw();
    
        }
        @Override
        public void show() {
    
        }
    
    
    
        @Override
        public void resize(int width, int height) {
    
        }
    
        @Override
        public void pause() {
    
        }
    
        @Override
        public void resume() {
    
        }
    
        @Override
        public void hide() {
    
        }
    
        @Override
        public void dispose() {
    
        }
    }
    

1 个答案:

答案 0 :(得分:0)

嗯,首先,你的结构是有缺陷的。 你的getState不只是返回一个状态。在你回国之前,很多事情都在发生。你应该真正移动那些东西,并在你改变状态后进行。

我没看到State.PLAYING?你只有2个状态DEAD和SUCCESS

你停止背景音乐:

Fruits.manager.get("music/Backmusic.ogg", Music.class).stop();

但看起来你再也不会重新开始了。