我正在使用最近每日构建的Corona SDK(版本 2001.562)为现有应用程序添加陀螺仪支持。不幸的是,我似乎无法获得event-handling
陀螺仪触发的功能。该应用程序在iPod touch 版本 4.3.3上运行。
我将陀螺仪连接到一个事件处理程序,如下所示:
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
包含带有 atimestamp
和“陀螺仪开启”的行。目前很好!
关于事件处理功能:
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
文件中!
请指教。提前致谢!