开发者

Coronasdk: About Factory Pattern and Corona Forum

I am new to corona and I tried to post in forum but I do not how. I could not find button or link liked "new thread", what should I do?

I also have a question about Factory pattern in corona. I tried to make myImage.lua which works liked factory function.

--in myImage.lua (I created global function)

function a(path)

  local b = display.newImage(path)

(another setting)

  return b;

end
开发者_StackOverflow社区

I found that when I call this function in main.lua, the function give me just one image no matter how many time I called function. So I guessed that this is not factory function. I wonder that is there somehow that I can create function which return new item+different item(not reference the existed one) every times that I called


Try adding it to a display group. That should retain the images.

--Global variable:
local images = display.newGroup()

function a(path)

  local b = display.newImage(path)
  (another setting)
  images:insert(b)

end

Oh, and you have to buy the thing before you can use the forums.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜