我正在从一本书中学习方向。我对代码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