电晕覆盖不显示

Corona Overlay doesn't show

我在场景之间创建加载场景时遇到问题,我得到的解决方案是使用叠加层,我已经尝试了好几天,但由于某种原因我无法让它工作。我有两个场景,一个显示项目列表,另一个显示基于单击哪一行的文本页面。现在的问题是第一个场景,它显示列表,下载要显示的图像,当然这需要一段时间,所以每当我转换到那个屏幕时,应用程序似乎被冻结,而一切都在加载。

我发现它确实进入了覆盖场景,因为我放入其中的打印语句打印出来了,但它什么也没显示,当我删除了隐藏覆盖的代码之后,它似乎仍然挂起,它进入覆盖场景,不显示任何内容然后在最终显示覆盖之前渲染 table 所以不是显示覆盖,而是将所有内容加载到下面,然后隐藏覆盖,它似乎在当前场景中被冻结,加载下面的所有内容,显示覆盖,然后立即隐藏覆盖。

我的三个场景的代码在下面,我现在发布的那个是唯一一个实际工作过一次然后就再也没有工作过的代码,它显示了叠加层,同时一切都按我想要的方式加载但出于某种原因,它那一次之后再也没有工作过。我对此感到非常沮丧,没有论坛给我提供解决方案,我真的很感激一些帮助。谢谢!

ItemListPage.lua

local composer = require ( "composer" )
local widget = require( "widget" )
local json = require( "json" )

-- Load the relevant LuaSocket modules
local http = require( "socket.http" )
local ltn12 = require( "ltn12" )

local scene = composer.newScene()


--NavigationBar elements initiated
--Removed for readability


--image handler
local function networkListener( event )
    if ( event.isError ) then
        print ( "Network error - download failed" )
    end

    print ( "event.response.fullPath: ", event.response.fullPath )
    print ( "event.response.filename: ", event.response.filename )
    print ( "event.response.baseDirectory: ", event.response.baseDirectory )
end


local function onRowRender( event )

    -- Get reference to the row group
    local row = event.row
    local params=event.row.params
    local itemRow=3;

    -- Cache the row "contentWidth" and "contentHeight" because the row bounds can change as children objects are added
    local rowHeight = row.contentHeight
    local rowWidth = row.contentWidth

    row.rowTitle = display.newText( row, params.topic, 0, 0, nil, 14 )
    row.rowTitle:setFillColor( 0 )
    row.rowTitle.anchorX = 0
    row.rowTitle.x = 0
    row.rowTitle.y = (rowHeight/2) * 0.5

    --Other elements removed for readabilty (it's all just text objects)

    --Download Image
    --params referring to items[i]
    local imagelink =params.imagelink

    -- Create local file for saving data
    local path = system.pathForFile( params.imagename, system.TemporaryDirectory )
    myFile = io.open( path, "w+b" ) 

    -- Request remote file and save data to local file
    http.request{
        url = imagelink, 
        sink = ltn12.sink.file( myFile )
    }

    row.Image = display.newImageRect(row, params.imagename, system.TemporaryDirectory, 25, 25)
    row.Image.x = 20
    row.Image.y = (rowHeight/2) * 1.5

    row:insert( row.rowTitle )
    row:insert( row.Image )
end

local function onRowTouch( event )
    local row = event.target
    local params=event.target.params

    composer.removeScene(composer.getSceneName("current"))
composer.gotoScene( "itempage" , {params=params})

end


function scene:create( event )
    local sceneGroup = self.view

end

function scene:show( event )
    local sceneGroup = self.view
    local phase = event.phase

    if phase == "will" then
        -- Called when the scene is still off screen and is about to move on screen
        --overlay
        composer.showOverlay( "loading", { isModal = true })

    elseif phase == "did" then

        --Table stuff
        local scrollBarOptions = {
            sheet = scrollBarSheet,  -- Reference to the image sheet
            topFrame = 1,            -- Number of the "top" frame
            middleFrame = 2,         -- Number of the "middle" frame
            bottomFrame = 3          -- Number of the "bottom" frame
        }
        -- Table
        local tableView = widget.newTableView(
            {
                left = 0,
                top = navBar.height,
                height = display.contentHeight-navBar.height,
                width = display.contentWidth,
                onRowRender = onRowRender,
                onRowTouch = onRowTouch,
                listener = scrollListener
            }
        )

        --json work
        local filename = system.pathForFile( "items.json", system.ResourceDirectory )
        local decoded, pos, msg = json.decodeFile( filename )

        if not decoded then
            print( "Decode failed at "..tostring(pos)..": "..tostring(msg) )
        else
            print( "File successfully decoded!" )
        end
        local items=decoded.items

        -- create a white background to fill screen
        local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )
        background:setFillColor( 1 )    -- white
        sceneGroup:insert( background )

        -- Insert rows
        for i = 1, #items do
            -- Insert a row into the tableView
            print( "Adding a row!" )
            tableView:insertRow{
                rowHeight = 100,
                rowColor = { default={ 0.8, 0.8, 0.8, 0.8 } },
                lineColor = { 1, 0, 0 },
                params=items[i]
            }
        end

        sceneGroup:insert( tableView )

        composer.hideOverlay( "fade", 100 )
    end 
end

-- other functions and elements unused and removed for readability

loading.lua

local composer = require ( "composer" )
local widget = require( "widget" )
local json = require( "json" )
local scene = composer.newScene()

-- Create the widget
function scene:create( event )
    local sceneGroup = self.view
    local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )
    background:setFillColor( 1 )    -- white

    local text = display.newText( "Loading scene", 0, 0, nil, 14 )
    text:setFillColor( 0 )
    text.anchorX = display.contentCenterX
    text.x = display.contentCenterX
    text.y = display.contentCenterY

    sceneGroup:insert( background )
    sceneGroup:insert( text )
    print ( "In loading create")

end


function scene:show( event )
    local sceneGroup = self.view
    local phase = event.phase

    if phase == "will" then

    elseif phase == "did" then

        print ( "In loading show")
    end 
end

-- other functions and elements unused and removed for readability

ItemDisplayPage.lua

local composer = require ( "composer" )
local widget = require( "widget" )
local json = require( "json" )
local scene = composer.newScene()


--NavigationBar elements initiated
--This creates the "back button", when clicked it returns to the previous scene, in this case "itemListPage"
--it takes, no parameters
local function handleLeftButton( event )
   if ( event.phase == "ended" ) then
        composer.removeScene(composer.getSceneName("current"))
    composer.gotoScene(composer.getSceneName("previous"))
   end
   return true
end
--Remaining navbar elements removed for readability

function scene:create( event )
local sceneGroup = self.view
local params=event.params

-- create a white background to fill screen
local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight )
background:setFillColor( 1 )    -- white

--creating header bar
local bar = display.newRect( navBar.height + (headerBarHeight*0.5), display.contentCenterY, display.contentWidth, headerBarHeight )
bar:setFillColor( 1 )

-- create stuff
local title = display.newText(params.topic, 0, 0, nil, 14 )
title:setFillColor( 0 )
title.anchorX = 0
title.x = margin
title.y = ((2*headerBarHeight/2) * 0.5)+navBar.height

local Image = display.newImageRect(params.imagename, system.TemporaryDirectory, 25, 25)
Image.x = 50
Image.y = display.contentCenterY


-- all objects must be added to group (e.g. self.view)
sceneGroup:insert( background )
sceneGroup:insert( title )
sceneGroup:insert( Image)

end
-- other functions and elements unused and removed for readability

我建议您不要使用 scene.show 事件进行加载。

使用timer.performWithDelay加载所有数据:

--in scene:show
elseif phase == "did" then
  timer.performWithDelay(0, function()
    local scrollBarOptions = {
    --put your code here
    composer.hideOverlay( "fade", 100 )
  end)

您当前的代码未显示覆盖,因为引擎在渲染任何内容之前等待 scene:show 事件。因此,叠加层和图像的渲染发生在所有图像加载完成后

在我的代码中 timer.performWithDelay 不会阻止 scene:show 执行,因此您会在加载图像之前看到渲染的叠加层