Thursday, 17 November 2011

Corona SDK Device Testing Tips

Having spent a couple of days working with Corona SDK my first challenge with it was how cumbersome it was to compile to a device. I admit at this point I am only on the free version but the concept of remote builds has never sat well with me, what happens if my internet connection goes down?

That aside, because I could pay to upgrade and get faster builds, the one thing which was proving a bind was the way to get the app onto the device to test. The steps to do this are:
  • Change to device build in the Corona Simulator
  • Wait for remote build to connect and build your solution and create compiled app
  • Connect device to machine
  • Open Organiser and drag app file to device and into Applications folder
  • Test
This becomes very laborious when its simple things you want to test regularly such as accelerometer and physics development.

Because I have done some work with XCode in the past I had become very used to plugging in my device and it all compiling nicely to device without any manual steps. I feared for my long turn future with Corona SDK if this was the development / testing cycle.

Thankfully tonight I came across a little gem. That little gem is Corona Remote by Matthew Pringle, an incredibly handy remote accelerometer app.

The premiss is that because the Corona simulator can't simulate the accelerometers data the app will do this for you by moving the device around as normal. The coronaremote app connects via your WIFI connection to your working machine's ip address and an open port of 8080 (check you firewall is open). All you then have to do is include the remote.lua file within your folder and add the following code within your app:

-- Load The Remote
local remote = require("remote")

-- Start The Remote On Port 8080
remote.startServer( "8080" )

-- Start The Compass ( if you want to use it )

-- Get The Latest Accelerometer Values
local function updateAccelerometer()

    -- This Runtime Listener Is An Example Of How To
    -- Access The Remote You Can Query remote.xGravity
    -- Or Any Other Value From Anywhere In Your Application

    local xGravity = remote.xGravity
    local yGravity = remote.yGravity
    local zGravity = remote.zGravity
    local xInstant = remote.xInstant
    local yInstant = remote.yInstant
    local zInstant = remote.zInstant
    local isShake = remote.isShake
    -- Only Use If Compass Activated And Running v1.1 Or Later
    local magnetic = remote.magnetic

    -- Print xGravity To Terminal
    print( remote.xGravity )


-- Add Enter Frame Listener
Runtime:addEventListener( "enterFrame" , updateAccelerometer )

With a valid connection the simulator picks up the accelerometer data and reacts and simulates to your devices movements, magic!!

The app can be downloaded via App Store and worth every penny.


Post a Comment