【问题标题】:Recent gyroscope support from Corona SDK seems to be non-responsive最近来自 Corona SDK 的陀螺仪支持似乎没有响应
【发布时间】: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


【解决方案1】:

问题是 event.deltaRotation 不存在。您可能指的是 event.deltaTime。

然后当你连接一个 nil 值时,Lua 会抛出一个错误,你的编写代码永远不会完成。 (当您在设备上遇到 Lua 错误时,最新的每日构建现在会打印出一条消息。)

文档展示了如何计算您自己的 deltaDegrees 或 deltaRadians: http://developer.anscamobile.com/reference/index/events/gyroscope/eventxrotation

【讨论】:

    【解决方案2】:

    只是一个疯狂的猜测,但可能从未调用过您的侦听器 --- 我注意到您的 onGyroscopeDataReceived 函数是本地的。如果是这种情况,那么您需要确保在调用 addEventListener 之前声明了变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-16
      • 1970-01-01
      相关资源
      最近更新 更多