1 回答
TA贡献2039条经验 获得超7个赞
假设你if(velocity.y != 0 || velocity.x != 0)经常检查,你确实会拉开很多循环。诀窍是检查“玩家是否在移动,我上次看时他们还在吗?” 而不仅仅是“玩家在移动”。
一种简单的方法是设置一个布尔标志:
//Sets the footstep sound. i.e. it changes to a grass soundfile when you walk on grass.
String footstepsFilePath = gameMap.getTileSoundFilePath(rect);
setFootsteps(Gdx.audio.newSound(Gdx.files.internal(footstepsFilePath)));
boolean isMoving = false;
//velocity is the speed at which the player is going in the x or y direction.
if((velocity.y != 0 || velocity.x != 0) && !isMoving) {
isMoving = true;
footsteps.loop();
}
if((velocity.y == 0 && velocity.x == 0) && isMoving) {
footsteps.stop();
isMoving = false;
}
我不完全确定为什么stop在您的情况下不起作用。但是,其他两个loop重载的文档说明
您需要使用返回的 ID 调用 stop(long) 来停止声音。
也许stop您正在使用的版本不起作用,或者它等待当前循环完成?
添加回答
举报