Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mobile CORONA SDK(LUA)中的显示组_Mobile_Lua_Coronasdk - Fatal编程技术网

Mobile CORONA SDK(LUA)中的显示组

Mobile CORONA SDK(LUA)中的显示组,mobile,lua,coronasdk,Mobile,Lua,Coronasdk,我创建了一个本地组,并在屏幕上将对象作为矩形插入其中,然后使用myGroup:removeSelf()和myGroup=nil。矩形和所有其他元素的内存是否也会自动清空?(下一代码) 还有其他问题。如何在createScene函数中使用cenarioGrupo,而它仅在函数criarCenario中创建?还吗?全面创建它 local function criarCenario() cenarioGrupo = display.newGroup() local chao = di

我创建了一个本地组,并在屏幕上将对象作为矩形插入其中,然后使用myGroup:removeSelf()和myGroup=nil。矩形和所有其他元素的内存是否也会自动清空?(下一代码)

还有其他问题。如何在createScene函数中使用cenarioGrupo,而它仅在函数criarCenario中创建?还吗?全面创建它

local function criarCenario()
    cenarioGrupo = display.newGroup()

    local chao = display.newRect( display.contentWidth*0.5, display.contentHeight*0.95, display.contentWidth, display.contentHeight*0.1 )
    chao:setFillColor(1,1,1)

    cenarioGrupo:insert(chao)
end


function scene:createScene( event )
      local sceneGroup = self.view
      criarCenario()
end

在Corona中,如果您创建一个显示组并向其中添加显示对象(不是android的本机小部件),当您尝试删除显示组时,它的所有子项和容器也将被删除

关于第二个问题: 您可以使用场景组作为criarCenario的条目,如下所示:

function scene:createScene( event )
    local sceneGroup = self.view
    criarCenario(sceneGroup)
end
然后在函数中,只需将显示组插入到场景组:

local function criarCenario(sceneGroup) -- use an entry
    cenarioGrupo = display.newGroup()


local chao = display.newRect( display.contentWidth*0.5, display.contentHeight*0.95, display.contentWidth, display.contentHeight*0.1 )


 chao:setFillColor(1,1,1)
cenarioGrupo:insert(chao)
sceneGroup:insert(cenarioGrupo) -- here is the main change
end
您还可以通过返回cenarioGrupo并将其插入CreateSecene中的sceneGroup来完成此操作:

local function criarCenario()
    cenarioGrupo = display.newGroup()
    local chao = display.newRect( display.contentWidth*0.5, display.contentHeight*0.95, display.contentWidth, display.contentHeight*0.1 )
    chao:setFillColor(1,1,1)

    cenarioGrupo:insert(chao)
    return cenarioGrupo
end

function scene:createScene( event )
      local sceneGroup = self.view
      sceneGroup:insert( criarCenario() )
end
我自己更喜欢第二种方法,因为它提供了更松散的耦合。在第二种方法中,criarCenario函数与createScene更为分离

local function criarCenario()
    cenarioGrupo = display.newGroup()
    local chao = display.newRect( display.contentWidth*0.5, display.contentHeight*0.95, display.contentWidth, display.contentHeight*0.1 )
    chao:setFillColor(1,1,1)

    cenarioGrupo:insert(chao)
    return cenarioGrupo
end

function scene:createScene( event )
      local sceneGroup = self.view
      sceneGroup:insert( criarCenario() )
end