我在GDX中有这个错误

时间:2018-04-05 19:05:10

标签: libgdx

它奏效了!
但是,当我查看我的Bullet课程时,它不起作用并给我一个错误!

此错误:

  

线程中的异常" LWJGL应用程序" com.badlogic.gdx.utils.GdxRuntimeException:#iterator()不能嵌套使用。在
  com.badlogic.gdx.utils.Array $ ArrayIterator.hasNext(Array.java:577)       在com.myflappyoyun.game.states.PlayState.update(PlayState.java:53)       在com.myflappyoyun.game.states.GameStateManager.update(GameStateManager.java:25)       在com.myflappyoyun.game.FlappyDemo.render(FlappyDemo.java:36)       在com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:225)       在com.badlogic.gdx.backends.lwjgl.LwjglApplication $ 1.run(LwjglApplication.java:126)

该过程以退出代码0

结束



public class PlayState extends state {
    private static final int TUBE_SPACING = 125;
    private static final int TUBE_COUNT = 4;
    private static final int GROUND_Y_OFFSET = -50 ;

    private Bird bird;
    private Texture bg;
    private Texture ground;
    private Vector2 groundPos1 , groundPos2 ;
    private Array<Tube> tubes ;

    public PlayState(GameStateManager gsm) {
        super(gsm);
        bird= new Bird(50 , 300);
        cam.setToOrtho(false, FlappyDemo.WIDTH/ 2, FlappyDemo.HEIGHT/ 2);
        bg = new Texture("bg.png");
        ground = new Texture("ground.png");
        groundPos1 = new Vector2(cam.position.x - cam.viewportWidth / 2, GROUND_Y_OFFSET);
        groundPos2 = new Vector2((cam.position.x - cam.viewportWidth / 2) + ground.getWidth(), GROUND_Y_OFFSET);

        tubes = new Array<Tube>();

        for (int i = 1; i < TUBE_COUNT ; i++) {
            tubes.add(new Tube(i * (TUBE_SPACING + Tube.TUBE_WIDTH)));
        }
    }

    @Override
    protected void handleInput() {
        if (Gdx.input.justTouched())
            bird.jump();

    }

    @Override
    public void update(float dt) {
        handleInput();
        updateGround();
        bird.update(dt);
        cam.position.x = bird.getPosition().x + 80 ;

        for (Tube tube : tubes) {
            if (cam.position.x - (cam.viewportWidth/ 2) > tube.getPosTopTube().x + tube.getTopTube().getWidth()){
                tube.reposition(tube.getPosTopTube().x + ((Tube.TUBE_WIDTH + TUBE_SPACING) * TUBE_COUNT));
            }
            if (tube.collides(bird.getBounds()))
                gsm.set(new PlayState(gsm));
        }
        if (bird.getPosition().y <= ground.getHeight() + GROUND_Y_OFFSET)
            gsm.set(new PlayState(gsm));
    cam.update();
    }

    @Override
    public void render(SpriteBatch sb) {
        sb.setProjectionMatrix(cam.combined);
        sb.begin();
        sb.draw(bg , cam.position.x - (cam.viewportWidth / 2), 0);
        sb.draw(bird.getTexture(), bird.getPosition().x,bird.getPosition().y);
        for (Tube tube : tubes) {
            sb.draw(tube.getTopTube(), bird.getPosition().x, tube.getPosTopTube().y);
            sb.draw(tube.getBottomTube(), tube.getPosBotTube().x, tube.getPosBotTube().y);
        }
        sb.draw(ground, groundPos1.x, groundPos1.y);
        sb.draw(ground, groundPos2.x, groundPos2.y);
        sb.end();

    }

    @Override
    public void dispose() {
        bg.dispose();
        bird.dispose();
        ground.dispose();
        for (Tube tube : tubes)
            tube.dispose();
        System.out.println("Play State Disposed");

    }
    private void updateGround() {
        if (cam.position.x - (cam.viewportWidth / 2) > groundPos1.x + ground.getWidth())
            groundPos1.add(ground.getWidth()*2, 0);
        if (cam.position.x - (cam.viewportWidth / 2) > groundPos2.x + ground.getWidth())
            groundPos2.add(ground.getWidth()*2, 0);
    }
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

看起来你可能应该只是改变管子&#39;到ArrayList的类型,如下所示:

ArrayList<Tube> tubes = new ArrayList<Tubes>();

使用不同类型的收藏品可能会更好。根据您最终使用管道的方式,检查here以获取一些想法。查看&#39; List&#39;

的实施类