我正在從一本書中學習方向。我對代碼event.type非常困惑。困惑於event.type Lua
下面是書中的代碼:
portrait = display.newText ("Portrait", display.contentWidth/2,display.contentHeight/ 2, nil,20)
portrait: setFillColor (1,1,1)
portrait.alpha = 1
landscape = display.newText ("Landscape", display.contentWidth/ 2, display.contentHeight /2, nil, 20)
landscape: setFillColor (1,1,1)
landscape.alpha = 0
local function onOrientationChange (event)
if (event.type == 'landscapeRight' or event.type == 'landscapeLeft') then
local newAngle = landscape.rotation - event.delta
transition.to (landscape, {time = 1500, rotation = newAngle})
transition.to (portrait, {rotation = newAngle})
portrait.alpha = 0
landscape.alpha = 1
else
local newAngle = portrait.rotation - event.delta
transition.to (portrait, {time = 150, rotation = newAngle})
transition.to (landscape, {rotation = newAngle})
portrait.alpha = 1
landscape.alpha = 0
end
end
好像整個方向改變功能工作圍繞event.type。我不明白它是什麼,我不明白它是什麼(==
)。此外,當我更改字符串(在本例中爲'landscapeRight'和'landscapeLeft')時,它也是一樣的。它會採取任何價值,仍然可以正常工作。我對它的工作原理感到困惑,請解釋event.type。
+1我添加了一個答案 – Schollii