【发布时间】:2011-07-06 23:23:15
【问题描述】:
我正在使用 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 包含带有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 文件中!
请指教。提前致谢!
【问题讨论】:
-
我怀疑问题可能出在我的设备上,但我在另一台 iPod touch 4.3.3 版上尝试了上述代码,结果同样令人失望。
标签: iphone coronasdk gyroscope