SO I'm trying to build something vaguely similar to one of my favorite child hood video games,
Star Control. I'm having a slow start with an extremely busy schedule and various things getting me side tracked. I'm starting to learn more about Lua and Gideros and have even started playing with ZeroBrane for live coding! (Pretty cool stuff!) Anyhow, I'm fooling with sounds and I've mocked up my very first Gideros class called Multi-sound. The idea is to play 2 or more sounds in succession with the last sound on a continuous loop until some event occurs. The purpose is to build a multi-stage laser sound which powers up when fired but continuously pulses while you hold the fire button. I'm going to post my naive code here for feedback. Has anyone done something similar? Am I following any bad practices? Please comment on code and direction as I have no clue what I'm doing, just having fun doing it!
MultiSound = {}
meta = {}
function MultiSound:new(soundFiles)
self.soundFiles = soundFiles
return self
end
function MultiSound:play()
local index = 1
local sound = Sound.new(self.soundFiles[index])
index = index+1
self.sound_channel = sound:play()
local sound_channel_callback = function()
if index==#self.soundFiles then
self.sound_channel = Sound.new(self.soundFiles[index]):play(0, math.huge)
else
self.sound_channel = Sound.new(self.soundFiles[index]):play()
index = index+1
self.sound_channel:addEventListener(Event.COMPLETE,sound_channel_callback)
end
end
self.sound_channel:addEventListener(Event.COMPLETE, sound_channel_callback)
end
function MultiSound:stop()
self.sound_channel:stop()
end |
Comments