Is there any way to return a displaygroup as the object of a metatable “class” module?
i went with this in the end
main.lua
[lua]local MenuCreator = require(“MenuCreator”)
local mc = MenuCreator:new() – creates “class” object
local menu = MenuCreator:create(“main”) – returns display object
menu.x=100
menu.y=50[/lua]
MenuCreator.lua
[lua]module(…, package.seeall)
MenuCreator = {}
MenuCreator_mt = (__index=MenuCreator)
function MenuCreator::new()
local self = {}
setmetatable(self, MenuCreator_mt)
return self
end
function MenuCreator::create(id)
local g = display.newGroup()
– graphics stuff etc
g.id = id
return g
end[/lua]
as opposed to
[lua]local MainMenu = require(“MainMenu”)
local menu = MainMenu:new() – no way to return as a displaygroup this way?
menu.x=100
menu.y=50[/lua]
[import]uid: 6645 topic_id: 6237 reply_id: 306237[/import]
