开发者

Recent gyroscope support from Corona SDK seems to be non-responsive

I'm using a recent daily build of 开发者_StackOverflowthe 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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜