Corona SDK 最近的陀螺仪支持似乎没有响应

发布于 2024-11-19 07:43:17 字数 1261 浏览 9 评论 0原文

我正在使用最近每日构建的 Corona SDK(版本 2001.562)向现有应用程序添加陀螺仪支持。不幸的是,我似乎无法让陀螺仪触发事件处理功能。该应用程序在 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 包含带有 的行时间戳和“陀螺仪打开”。到目前为止还不错!

关于事件处理函数:

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 文件中!

请指教。提前致谢!

I'm using a recent daily build of the Corona SDK (version 2001.562) to add gyroscope support to an existing application. Unfortunately, I can't seem to get the event-handling function for the gyroscope to fire. The application is running on an iPod touch, version 4.3.3.

I attach the gyroscope to an event handler like so:

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

When I launch the application on the device, then close it and download the resource files, I find that log.txt contains the line with a timestamp and "gyroscope on". Good so far!

On to the event-handling function:

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

This line of information never appears in the log.txt file!

Please advise. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2024-11-26 07:43:17

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

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

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

The problem is event.deltaRotation doesn't exist. You might mean event.deltaTime.

Then when you concatenate a nil value, Lua throws an error and your write code never gets completed. (The latest daily build will now print out a message when you encounter a Lua error on a device.)

The documentation shows how to compute your own deltaDegrees or deltaRadians:
http://developer.anscamobile.com/reference/index/events/gyroscope/eventxrotation

难如初 2024-11-26 07:43:17

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

Just a wild guess but it may be your listener is never called --- I noticed your onGyroscopeDataReceived function is local. If that's the case, then you need to make sure the variable is declared prior to the addEventListener call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文