2011-07-06 30 views
1

我正在使用最近的每日編譯的Corona SDK(版本2001.562)將陀螺儀支持添加到現有的應用程序。不幸的是,我似乎無法獲得用於陀螺儀發射的event-handling功能。該應用程序在iPod touch上運行,版本4.3.3來自Corona SDK的最新陀螺儀支持似乎不響應

我的陀螺儀連接到事件處理程序,像這樣:

if system.hasEventSource("gyroscope") then 
    feedbackFile = io.open(system.pathForFile("log.txt", system.DocumentsDirectory), "a"); 
    feedbackFile:write((os.clock()-startupTime).."\tgyroscope on\n"); 
    io.close(feedbackFile); 
    Runtime:addEventListener("gyroscope", onGyroscopeDataReceived) 
else 
    feedbackFile = io.open(system.pathForFile("log.txt", system.DocumentsDirectory), "a"); 
    feedbackFile:write((os.clock()-startupTime).."\tgyroscope off\n"); 
    io.close(feedbackFile); 
end 

當我啓動設備上的應用程序,然後將其關閉並下載資源文件,我發現log.txt包含與timestamp行和「陀螺儀上」。目前很好!

在該事件處理函數:

local function onGyroscopeDataReceived(event) 

    feedbackFile = io.open(system.pathForFile("log.txt", system.DocumentsDirectory), "a"); 
    feedbackFile:write((os.clock()-startupTime).."\tgyroscope reading delta="..event.deltaRotation..",x="..event.xRotation..",y="..event.yRotation..",z="..event.zRotation.."\n"); 
    io.close(feedbackFile); 
end 

的信息,該行不會出現在log.txt文件!

請指教。提前致謝!

+0

我懷疑問題可能在於與我的設備,但我在另一個iPod touch 4.3.3版上試過上面的代碼,並得到了同樣令人失望的結果。 – JDT

回答

0

只是一個瘋狂的猜測,但它可能是你的聽衆是從來沒有叫過---我注意到你的onGyroscopeDataReceived函數是本地的。如果是這種情況,那麼你需要確保變量在addEventListener調用之前被聲明。

2

問題是event.deltaRotation不存在。你可能意思是event.deltaTime。

然後當你連接一個零值時,Lua會拋出一個錯誤,你的編寫代碼永遠不會完成。 (當你遇到一個設備上的Lua錯誤最新的每日構建現在打印出消息)

文檔顯示如何計算自己的deltaDegrees或deltaRadians: http://developer.anscamobile.com/reference/index/events/gyroscope/eventxrotation