Libgdx HTML5 AnimationScheduler长度为空

问题描述 投票:0回答:1

我创建了一个libdx游戏,它在Android和桌面版本中运行良好。在游戏中,我有一只苍蝇的鸟,必须避开其他物体。如果它与对象接触,则游戏结束并且屏幕上出现游戏。

在我的GWT应用程序中,第一次出现在屏幕上的游戏我没有问题,但是如果我重新开始游戏并再次玩,那么我会收到一个错误:enter image description here

在Google Chrome控制台中,错误发生在javascript的“throw new RuntimeException(t)”行中。我对Javascript不太熟悉。有没有人在使用动画调度程序之前遇到过类似的问题?

AnimationScheduler.get().requestAnimationFrame(new AnimationCallback() {
			@Override
			public void execute (double timestamp) {
				try {
					mainLoop();
				} catch (Throwable t) {
					error("GwtApplication", "exception: " + t.getMessage(), t);
					throw new RuntimeException(t);
				}
				AnimationScheduler.get().requestAnimationFrame(this, graphics.canvas);
			}
		}, graphics.canvas);
	}

在我的Libgdx核心代码中,当鸟崩溃并且游戏结束时会调用以下行代码,因此可能发生错误:

 Gdx.app.postRunnable(new Runnable() {

            @Override
            public void run() {
                Sounds.gameOverSound.play(SettingsManager.gameVolume);
                highScore.stopCounting();
                for (Dodgeable dodgeable : dodgeables.activeDodgeables) {
                    dodgeable.reset();
                }
                dodgeables.resetSpawnTimes();
                for (Sound sound : Sounds.activeSounds){
                    //Stop all sounds currently playing
                    sound.stop();
                    Sounds.activeSounds.remove(sound);
                }
                //Reset all notifications that are active so they stop displaying
                Notifications.ExclamationMark.resetNotifications();
                Array<Body> bodies = new Array<Body>();
                world.getBodies(bodies);
                for (int i = 0; i < bodies.size; i++) {
                    world.destroyBody(bodies.get(i));
                }
                dispose();
                game.setScreen(new GameOverScreen(game, playServices, databaseAndPreferenceManager, highScore));
            }
        });
javascript java gwt libgdx
1个回答
1
投票

解决了......事实证明,在我的“dispose()”方法中,我从另一个类中处理了一个声音而没有重新创建声音。因此,我正在处理导致错误的空声音。

© www.soinside.com 2019 - 2024. All rights reserved.