简体   繁体   English

Corona SDK:Director类和分组对象

[英]Corona SDK : Director Class and Grouping objects

I've got a problem about Director class and grouping some objects on an external class. 我有一个关于Director类的问题,并在外部类上对一些对象进行分组。 Here is my scripts of short example application. 这是我的简短示例应用程序的脚本。

main.lua main.lua

gameScene.lua gameScene.lua

fakeScene.lua fakeScene.lua

theClass.lua theClass.lua

Do not be lazy to glance, scripts are very short :) 不要懒得一眼,脚本很短:)

At the bottom of "theClass.lua" script, there is a line like that : "theGroup:insert(back)" 在“theClass.lua”脚本的底部,有一行如下:“theGroup:insert(back)”

When I comment this line, there is no problem about application, but I need to group some objects in this theClass module. 当我评论这一行时,应用程序没有问题,但我需要在这个theClass模块中对一些对象进行分组。 How can I fix this problem? 我该如何解决这个问题?

Thanks a lot! 非常感谢!

Try returning the variable into a table using 尝试使用将表中的变量返回到表中

local function theFunc(localGroupValue)
 localGroup = localGroupValue
 local back = display.newImage("background.png")
 back:setReferencePoint(display.TopLeftReferencePoint)
 back.x = 200
 back.y = 200

 return("back")

end

for s=1,#array do
 table.insert(array,theFunc())
end

and then insert the array into the group using 然后使用将数组插入组中

for s=1,#array do 
 theGroup:insert(array[s])
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM