Added assets manager singleton.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
local love = require 'love'
|
||||
local assets = require 'src.utils.asstmngr'
|
||||
local make_class = require 'src.utils.classes'
|
||||
local GameState = require 'src.gstates.gstate'
|
||||
local Fader = require 'src.graphics.fader'
|
||||
@@ -36,40 +37,37 @@ function MainMenu:_init(name, index)
|
||||
|
||||
-- Create sound effects.
|
||||
self.bgm = SoundEffect('bgm/eskisky.wav')
|
||||
end
|
||||
|
||||
|
||||
function MainMenu:load()
|
||||
-- Load sprites.
|
||||
self.background:load()
|
||||
self.cursor:load()
|
||||
|
||||
-- Load sound effects and start playing the background music
|
||||
self.bgm:load()
|
||||
self.bgm:play()
|
||||
-- Register all assets.
|
||||
assets:register(self.name, self.background)
|
||||
assets:register(self.name, self.cursor)
|
||||
assets:register(self.name, self.bgm)
|
||||
end
|
||||
|
||||
|
||||
function MainMenu:update(dt)
|
||||
-- Update the fader.
|
||||
self.fade:update(dt)
|
||||
if assets:done(self.name) then
|
||||
if not self.bgm:isPlaying() then self.bgm:play() end
|
||||
|
||||
-- Move on to the next game state if the user skipped the intro or all stages are complete.
|
||||
if not self.skip then return self.index else return -1 end
|
||||
-- Update the fader.
|
||||
self.fade:update(dt)
|
||||
|
||||
-- Move on to the next game state if the user skipped the intro or all stages are complete.
|
||||
if not self.skip then return self.index else return -1 end
|
||||
else
|
||||
assets:update(self.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function MainMenu:draw()
|
||||
self.background:draw()
|
||||
self.cursor:draw()
|
||||
self.fade:draw()
|
||||
end
|
||||
|
||||
|
||||
function MainMenu:unload()
|
||||
self.background:unload()
|
||||
self.cursor:unload()
|
||||
self.bgm:unload()
|
||||
if assets:done(self.name) then
|
||||
self.background:draw()
|
||||
self.cursor:draw()
|
||||
self.fade:draw()
|
||||
else
|
||||
assets:draw()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user