I'd like to create my own class that extends playdate.sound.sequence and adds a getVolume() and setVolume() function. How would I do this without having to copy all the function names listed in the sdk (like isPlaying() and getLength() )
You can't subclass playdate.sound.sequence
in the way you're used to from our object library (CoreLibs/object
), because it isn't implemented in that way. It's actually just a stub that provides a Lua interface to non-object-oriented C code.
But Lua is a very dynamic language, so you can add functions to it anyway:
playdate.sound.sequence.doThing = function(self)
-- do the thing
end
Then you can call mySequence:doThing()
as expected. (Note the self
argument above — this gets passed automatically when you use the colon syntax.)
2 Likes