我是lua的新手,并尝试查看其他类似错误的帖子。我无法解决我的问题。
我试图让我的数字对象在方向上使用alpha消失,并且出现正确放置的数字对象。我添加了onOrientationLeft函数和一个监听器。这样做后我收到了我的错误,无法弄清楚如何使它工作。我的代码中的注释将说明我正在尝试做的事情,请找到onOrientationLeft函数以及链接到它的最后一个运行时。
pZeroButton = display.newImage ("0.png",100, 470 )
llZeroButton = display.newImage ("0.png", 200,200)
llZeroButton.alpha = 0
pOneButton = display.newImage ("1.png",56,420)
pTwoButton = display.newImage ("2.png",123.5, 420)
pThreeButton = display.newImage ("3.png",191,420)
pFourButton = display.newImage ("4.png",56,370)
pFiveButton = display.newImage ("5.png",123.5, 370)
pSixButton = display.newImage ("6.png",191,370)
pSevenButton = display.newImage ("7.png",56,320 )
pEightButton = display.newImage ("8.png",123.5,320)
pNineButton = display.newImage ("9.png", 191, 320)
function onOrientationLeft ()
if (event.type == "landscapeRight") then
print ("Test if this function onOrientationLeft is working properly")
end
end
- [[我添加了这个函数试图让函数打印出字符串,但是 每次我在电晕SDK模拟器中旋转手机我都会尝试索引全局错误 - 'event'(零值) - ]]
function calculateZero(number)
local pZeroButton = display.newText (0, 300,30,nil,38)
pZeroButton: setFillColor (0,0,0)
return
end
function calculateOne(number)
local pOneButton = display.newText (1, 300,30,nil,38)
pOneButton: setFillColor (0,0,0)
return
end
function calculateTwo(number)
local pTwoButton = display.newText (2, 300,30,nil,38)
pTwoButton: setFillColor (0,0,0)
return
end
function calculateThree(number)
local pThreeButton = display.newText (3, 300,30,nil,38)
pThreeButton: setFillColor (0,0,0)
return
end
function calculateFour(number)
local pFourButton = display.newText (4, 300,30,nil,38)
pFourButton: setFillColor (0,0,0)
return
end
function calculateFive(number)
local pFiveButton = display.newText (5, 300,30,nil,38)
pFiveButton: setFillColor (0,0,0)
return
end
function calculateSix(number)
local pSixButton = display.newText (6, 300,30,nil,38)
pSixButton: setFillColor (0,0,0)
return
end
function calculateSeven(number)
local pSevenButton = display.newText (7, 300,30,nil,38)
pSevenButton: setFillColor (0,0,0)
return
end
function calculateEight(number)
local pEightButton = display.newText (8, 300,30,nil,38)
pEightButton: setFillColor (0,0,0)
return
end
function calculateNine(number)
local pNineButton = display.newText (9, 300,30,nil,38)
pNineButton: setFillColor (0,0,0)
return
end
pZeroButton : addEventListener ("tap", calculateZero)
pOneButton : addEventListener ("tap", calculateOne)
pTwoButton : addEventListener ("tap", calculateTwo)
pThreeButton : addEventListener ("tap", calculateThree)
pFourButton : addEventListener ("tap", calculateFour)
pFiveButton : addEventListener ("tap", calculateFive)
pSixButton : addEventListener ("tap", calculateSix)
pSevenButton : addEventListener ("tap", calculateSeven)
pEightButton : addEventListener ("tap", calculateEight)
pNineButton : addEventListener ("tap", calculateNine)
Runtime : addEventListener ("orientation", onOrientationLeft)
答案 0 :(得分:4)
你没有忘记回调中的event
参数吗?
像'尝试索引全局 - '事件'(零值)这样的错误通常与未声明的标识符有关。检查功能范围,你会发现错误导致它。
请参阅an example of orientation event
P.S。最好只发布最小部分代码,您可以重现错误。这部分也应该是可编译的。它将大大降低问题的复杂性,并导致更精确或更快的答案。请参阅SSCCE。