Fig*_*gör 1 lua class coronasdk
我正在使用导演类进行场景转换,我需要在另一个类的类中使用该变量.那我怎么称呼呢?
local a= require "welcome"
Run Code Online (Sandbox Code Playgroud)
variableName是welcome类中的文本显示对象
print(a.variableName.text)
Run Code Online (Sandbox Code Playgroud)
但是我没有.
你能救我吗?谢谢
使变量成为返回表的属性:
local Class = {}
function Class.new()
local class = {}
class.variableName = display.newText("Hello mom!", 100, 100, "Helvetica", 18)
return class
end
return Class
Run Code Online (Sandbox Code Playgroud)
然后你可以参考它:
local a = require ("class").new()
print(a.variableName.text)
Run Code Online (Sandbox Code Playgroud)
要么
如果要在Rauber的Director类中的屏幕之间传递变量,您可以:
local parameters = {p1="some text", p2="some more text"}
director:changeScene(parameters, "sceneName")
Run Code Online (Sandbox Code Playgroud)
在您的屏幕中,使新功能接受参数:
function new(parameters)
print(parameters.p1, parameters.p2) --> some text some more text
end
Run Code Online (Sandbox Code Playgroud)
要么
将_G放在变量前面
_G.myGlobalVar = "some awesome stuff"
Run Code Online (Sandbox Code Playgroud)
然后你可以在另一个类中引用它
print(_G.myGlobalVar) --> some awesome stuff
Run Code Online (Sandbox Code Playgroud)