I'm new to love, and lua in general. I love it so far.
I read alot of topics on here about OOP, and this isn't a love specific question but it seems it's a common topic, and I have an issue.
I'm using Bart's class lib. Here ( removed license for the sake of code length )
Code: Select all
__HAS_SECS_COMPATIBLE_CLASSES__ = true
local class_mt = {}
function class_mt:__index(key)
return self.__baseclass[key]
end
class = setmetatable({ __baseclass = {} }, class_mt)
function class:new(...)
local c = {}
c.__baseclass = self
setmetatable(c, getmetatable(self))
if c.init then
c:init(...)
end
return c
end
Code: Select all
--[[
@File: sound.lua
@Purpose:
--------------------------------------------------------
]]--
ZLove.Sound = {};
ZLove.Sound.internalObjects = {}; -- container full of sound objects
ZLove.Sound.Object = class:new();
function ZLove.Sound.Object:init( Source, sType, bPrecache )
bPrecache = bPrecache or false;
self.loveSource = {};
self.bPrecache = bPrecache;
self.bPlayed = false;
if( type( Source ) == "table" ) then
-- if we precache, we load all the sounds in the table
if( bPrecache ) then
for _, v in ipairs( Source ) do
table.insert( self.loveSource, { v, love.audio.newSource( v, sType ) } );
end
else
local iRndIndex = math.random( 1, #Source );
table.insert( self.loveSource, { Source[ iRndIndex ], love.audio.newSource( Source[ iRndIndex ], sType ) } );
end
else
table.insert( self.loveSource, { Source, love.audio.newSource( Source, sType ) } );
end
table.insert( ZLove.Sound.internalObjects, self );
end
function ZLove.Sound.Object:play()
self.loveSource[1][2]:play();
end
function ZLove.Sound:update( dt )
-- now we can loop through self.internalObjects
-- and control every sound object we've created
end
Code: Select all
local nSound = ZLove.Sound.Object:new( "sound.ogg", "static", false );
nSound:play();
Sorry if I wasn't to clear. This all works, but I'm not sure if i'm using OO abilities correctly.
Thanks!