Hi all.
So right now I’m trying to create an external module .lua file, only I’ve hit a wall with some of the options on the new object.
local soundBtn = {} local soundBtn\_mt = {\_\_index = soundBtn} function soundBtn.new ( text, ID, soundCue, yPos ) local newsoundBtn = { buttonImg = display.newImage ("button.png", display.contentWidth/2, (display.contentHeight\*0.15)\*yPos), buttonTxt = display.newText (text, display.contentWidth/2, (display.contentHeight\*0.15)\*yPos, "SHOWG.TTF", 90), } return setmetatable (newsoundBtn, soundBtn\_mt) end function soundBtn:tap( event ) audio.loadSound(soundCue) audio.play( soundCue) end return soundBtn
Here’s what I have so far.
My problem is that I can’t find a way to set things such as the text’s colour, or attach this ‘soundBtn:tap’ function as a listener to the ‘buttonImg’. How do I go about adjusting these kind of things within this module?
Another smaller problem I’m having is about using this entire object as one entity. For example, in my main.lua, I have this:
local soundBtn1 = soundBtn.new("test", 1, "audio.mp3", 4)
but then I also want to add this object to a scroll widget, but since it isn’t a display object it can’t be added, so I have to do something like this:
menuScroll:insert(soundBtn1.buttonImg) menuScroll:insert(soundBtn1.buttonTxt)
Is there some way I can add this soundBtn object and have it’s children (buttonImg buttonTxt) follow it?
Hope I make sense.
Thanks for reading.