第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何確保指定聲音只有 1 個實例在循環(huán)以及如何阻止它循環(huán)?

如何確保指定聲音只有 1 個實例在循環(huán)以及如何阻止它循環(huán)?

一只斗牛犬 2022-11-30 17:02:19
我目前正在開發(fā)一款游戲,在播放器更新方法中,我希望腳步Sound在玩家行走時開始循環(huán),我希望它在玩家停止行走時停止循環(huán)。但是,我無法弄清楚如何確保只有 1 個實例在Sound循環(huán)。澄清一下:我說的是gdx.audio.Sound課堂。這是我的代碼目前的樣子://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)));//velocity is the speed at which the player is going in the x or y direction.if(velocity.y != 0 || velocity.x != 0) footsteps.loop();if(velocity.y == 0 && velocity.x == 0) footsteps.stop();結(jié)果:當玩家開始移動時,大量腳步聲實例開始循環(huán)。當播放器停止移動時,所有播放器都會繼續(xù)循環(huán)。第一部分是出于顯而易見的原因,但我無法弄清楚如何確保只有一個實例在循環(huán)。但是對于第二部分,我不確定為什么不是所有的腳步聲實例都停止循環(huán),因為這是文檔中stop()所說的:停止播放此聲音的所有實例。
查看完整描述

1 回答

?
largeQ

TA貢獻2039條經(jīng)驗 獲得超8個贊

假設(shè)你if(velocity.y != 0 || velocity.x != 0)經(jīng)常檢查,你確實會拉開很多循環(huán)。訣竅是檢查“玩家是否在移動,我上次看時他們還在嗎?” 而不僅僅是“玩家在移動”。


一種簡單的方法是設(shè)置一個布爾標志:


//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 調(diào)用 stop(long) 來停止聲音。


也許stop您正在使用的版本不起作用,或者它等待當前循環(huán)完成?


查看完整回答
反對 回復(fù) 2022-11-30
  • 1 回答
  • 0 關(guān)注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號