簡體   English   中英

行觸摸的gotoScene的ID名稱為“ Corona SDK”

[英]Row touched gotoScene with id name “Corona SDK”

我正在嘗試通過行觸摸進入一個新場景。 我希望被觸摸的行以與ID名稱相同的文件名進入場景。 我希望這不要太令人困惑。 問題出在功能行觸摸中。 這是我的代碼。 先感謝您。

            local hike = {}
hike[1] = { name="Bell Canyon",    difficulty="Easy" }
hike[2] = { name="Donut Falls",  difficulty="Easy" }
hike[3] = { name="Hidden Peak",   difficulty="Medium" }
hike[4] = { name="Dog Lake",   difficulty="Easy" }
hike[5] = { name="Mary, Martha", difficulty="Easy" }
hike[6] = { name="Catherine",  difficulty="Easy" }

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

        local function onRowRender( event )

local row = event.row
   local id = row.index


   row.nameText = display.newText( hike[id].name, 12, 0, native.systemFont, 45 )
   row.nameText.anchorX = 0
   row.nameText.anchorY = 0.5
   row.nameText:setFillColor( 0 )
   row.nameText.y = 50
   row.nameText.x = 25

   row.difficultyText = display.newText( hike[id].difficulty, 12, 0, native.systemFont, 24 )
   row.difficultyText.anchorX = 0
   row.difficultyText.anchorY = 0.5
   row.difficultyText:setFillColor( 0.5 )
   row.difficultyText.y = 110
   row.difficultyText.x = 25


   row.arrow = display.newText( ">", 12, 0, native.systemFont, 35 )
   row.arrow.anchorX = 0
   row.arrow.anchorY = 0.5
   row.arrow:setFillColor( .5 )
   row.arrow.y = 110
   row.arrow.x = display.contentWidth - 50




   row:insert( row.nameText )
   row:insert( row.difficultyText )
   row:insert( row.arrow )
   return true
end



function RowTouch( event )
if event.phase == "release" then
    composer.gotoScene( event.target.hike[id].name )
    end 
end



 myTable = widget.newTableView
    {
        width = display.contentWidth, 
        height = display.contentHeight,
        backgroundColor = { .47, .66, .53 },
        topPadding = 0,
        hideBackground = false,
        onRowRender = onRowRender,
        onRowTouch = RowTouch,
        noLines = true,
    }



    for i=1, #hike do
        myTable:insertRow{
        rowHeight = 220,
        isCategory = false,
        lineColor = { .47, .66, .53 }
        }
    end
end

您可能應該在“遠足”表中添加一個額外的字段:

hike[1] = { name="Bell Canyon",    difficulty="Easy",  sceneName="bellcanyon" }

然后

composer.gotoScene( hike[event.target.index].sceneName )

這樣,您可以擁有一個供人類閱讀的顯示名稱,以及一個專用於作曲家場景的字符串。

嘗試寫作

composer.gotoScene( hike[event.target.index].name );

遠足名稱中包含空格和逗號,而不是最好的文件名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM