我正在使用最近的Corona (版本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和“陀螺仪on”的行。到目前为止还不错!
转到事件处理功能:
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文件中!
请给我建议。提前感谢!
发布于 2011-08-18 00:55:44
问题是event.deltaRotation不存在。你可能指的是event.deltaTime。
然后,当您连接一个零值时,Lua抛出一个错误,您的编写代码永远也不会完成。(当您在设备上遇到Lua错误时,最新的每日构建将打印一条消息。)
这些文档展示了如何计算您自己的deltaDegrees或deltaRadians:http://developer.anscamobile.com/reference/index/events/gyroscope/eventxrotation
发布于 2011-08-17 23:44:17
只是猜测一下,但可能你的听者从来没有被调用过--我注意到你的onGyroscopeDataReceived函数是本地的。如果是这样的话,那么您需要确保变量在addEventListener调用之前声明。
https://stackoverflow.com/questions/6604179
复制相似问题