尝试在动画过程中播放声音,但是动画的每一帧都播放一次声音

Turtsnaccko

就像标题所暗示的那样,我正在尝试在播放某个动画时播放声音,其他声音没有问题,通过推论,我得出结论,每次动画帧通过时声音就在循环播放。推测是鲨鱼与地雷发生碰撞,地雷爆炸,听到轰鸣声,游戏结束了。

编辑:仅当检测到碰撞时才调用“轰炸声”代码。玩家与收藏品碰撞时会发出另一种声音,但该声音效果很好。只有当玩家与地雷发生碰撞并且播放爆炸动画时,声音才会混乱。每当动画的一帧过去时,它都会重新启动。

 if (Intersector.overlaps(this.mineC[i], this.sharkC)) {
            this.boomsound.play();
            this.collision = true;
            this.gamestate = 2;
            this.runtime += Gdx.graphics.getDeltaTime();
            this.game.batch.draw((TextureRegion) this.boom.getKeyFrame(this.runtime, false), (float) (Gdx.graphics.getWidth() / 5), this.sharkY - 120.0f);

            this.boom.setPlayMode(PlayMode.NORMAL);
            if (this.boom.isAnimationFinished(this.runtime)) {
                boomsound.stop();
                this.game.setScreen(new GameOverShark(this.game));
            }
        }
斋月

this.boomsound.play() 在代码的每次迭代中都调用过,应该只调用一次

 // field
 private boolean boomNotStarted = true; 

 ....

 if (Intersector.overlaps(this.mineC[i], this.sharkC)) {
      if (boomNotStarted) {
            this.boomsound.play();
            this.boomNotStarted = false;
      }

      ...
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章