我正在重新创建一个旧的 16 位游戏。我正在创建通常显示在底部的聊天。每个句子都是逐字过渡的。
每次添加角色时,我都想让它发出小小的嘟嘟声。我有一个 wav 文件,其中包含一个听起来不错的短“blip”,问题是,当我每次都让它执行 blip 时,它通常会搞砸。
要么是:
- 跳过逐个字符的过程,只显示完整的单词和提示一次
- 滞后并正确执行几次 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
如果您能提供帮助,谢谢!如果您需要任何说明,我非常乐意提供帮助!