我正在重新創建一箇舊的16位遊戲。我正在創建通常顯示在底部的聊天。每個句子都逐字符轉換。播放Wav太快了混淆了
每次添加一個角色時,我都想讓它發出一點點響聲。我有一個包含一個簡短的'blip'的wav文件,聽起來是正確的,問題是,當我每次都做blip的時候,它通常會出現問題。
它要麼:
- 跳過字符一個字符的過程,只是顯示完整的單詞和光點一旦
- LAG和一對夫婦BIPS的正確做,然後做上述 列出什麼東西
這裏是它變得複雜。我爲此使用Lua和VB.net。引擎,我寫在VB.net中,而實際的遊戲機制和故事情節由Lua控制。
這裏是Lua的基本的這段:
RegisterEvent("ready", function()
_G.Chat={}
_G.Chat["busy"]=false
_G.Chat.Say=(function(from,msg,done)
if _G.Chat["busy"] then return end
_G.Chat["busy"]=true
local x,y=getRelativePositionOpposite(1024,192)
--Draw
local chatPanel=engine:AddSprite("chat.png",0,0,1024,192,x,y,1024,192,5)
local fromText=engine:AddString(from..":",x+25,y+25,"#FFFFFF",16,0,0)
local msgText=nil
local mx=string.len(msg)
--Chat Cleanup
setupCleanup=(function()
local g=true
RegisterEvent("keyup", function(key)
if not g then return end
if key=="Space" then
engine:RemoveSprite(chatPanel)
engine:RemoveString(fromText)
engine:RemoveString(msgText)
_G.Chat["busy"]=false
done()
g=false
end
end)
end)
doText=(function(i)
if msgText then
engine:RemoveString(msgText)
end
msgText=engine:AddString(string.sub(msg,1,i),x,y+75,"#FFFFFF",14,1,0)
engine:PlaySound("chatblip.wav")
if i>=mx then setupCleanup() return end
pause(.75,(function() doText(i+1) end))
end)
doText(1)
end)
end)
下面是暫停功能,僅供參考(在Lua):
_G.pause=(function(t,f)
if t and f then
local tt=engine.timer.ElapsedMilliseconds/1000+t
local lcc=true
engine.event_tick:add(function(nt)
if nt>=tt and lcc then
f()
lcc=false
end
end)
end
end)
下面是實際播放噪音的這段在VB.net:
Public Sub PlaySound(ByVal fileFullPath As String)
My.Computer.Audio.Play(My.Computer.FileSystem.CurrentDirectory & "\bin\sounds\" & fileFullPath, AudioPlayMode.Background)
End Sub
謝謝,如果你可以幫助!如果你需要任何澄清,我很樂意提供幫助!
哇,它工作完美!萬分感謝 :) – FreeSnow