Corona SDK Emitter Fireworks

After the launch of Hexium in December 2018 I have been adding more levels in patch releases, but finally after 80 levels I decided the next release would be the last to add new levels. My final level, level 85, would be the end game screen, congratulating the player on finishing the game.

I wanted a “fireworks” effect on the end game screen. Although I’ve been using Corona SDK for a few years I had never touched emitters, and this seemed like a perfect fit for them. After reading the docs on creating emitters I saw that they could be completely defined by a block of JSON, which would make it easy to reuse the fireworks display code to spawn multiple types of effects.

I created a simple mask for the first emitter using an image editing program (Adobe Fireworks – how appropriate!) and then created the JSON to define the emitter. The code to spawn a new emitter is easy, so my new effect was on screen almost immediately. The next hour was spent changing the parameters and reloading the scene until I was happy with the effect.

Next I created two more emitter masks, two more emitter JSON definitions, and then created a table to hold all of the emitters. Here is the final result:

You can download all of the code from Github here: https://github.com/prairiewest/corona-fireworks All of the content in this project were either created by me or has an open license (which I have included in the licenses folder), so you’re allowed to reuse as much of it as you want.

If you’re working on a game using Corona SDK please send me a message on Twitter, I’d like to see it: @toddtrann

Remember to Cancel Timers When App Is In The Background

I had been working on my latest mobile game Hexium for quite a few months, and it was time to put it into the hands of some testers.  Everything seemed to be going well, but then one of the testers said that their Android phone was giving them a warning about it consuming too much battery power when it was in the background.  I had never seen this warning myself, despite already testing the app on a few Android devices of my own.  He showed me the screen, and sure enough the warning was on screen and looking fairly scary.  As an end user, my first instinct on seeing a warning like that for a casual game would be to simply uninstall the app.  This was bad.

I looked over my code and didn’t see anything that could be causing the problem.  I went to the Corona Labs web site and found this excellent article on performance and optimization.  However after implementing all of the tips, the tester was still receiving the warning.

Then I found it: a timer.  I had a timer that was firing every second while the game was running, to check to see if the user had earned a free life.  Of course this timer didn’t need to run while the app was in the background.  So I added some code to catch the applicationSuspended event and cancel the timer, and gave the updated build to the tester.

Success!! Android no longer complained about the app using battery while in the background!

Here is a block of code that contains just enough to show you what events were caught, and how I stopped and restarted the timer:

local free_life_timer

local onSystem = function(event)
    if event.type == "applicationExit" then
        -- Cancel the free life timer
        if free_life_timer ~= nil then
            timer.cancel(free_life_timer)
        end

    elseif event.type == "applicationSuspend" then
        -- Cancel the free life timer
        if free_life_timer ~= nil then
            timer.cancel(free_life_timer)
        end

    elseif event.type == "applicationResume" then
        - Start a new free life timer
        free_life_timer = timer.performWithDelay(1000, function()
            update_free_lives()
        end, 0)
    end
end

function scene:show( event )
    local phase = event.phase

    if ( phase == "will" ) then
        -- setup a system event listener
        Runtime:addEventListener( "system", onSystem )
        
    elseif ( phase == "did" ) then
        -- Start the free life timer
        free_life_timer = timer.performWithDelay(1000, function()
            update_free_lives()
        end, 0)
	end

end


function scene:hide( event )
    local phase = event.phase

    if ( phase == "will" ) then
        -- Cancel the free life timer
        timer.cancel(free_life_timer)
        Runtime:removeEventListener( "system", onSystem )
    end
end

Latest Game Jam

Another game jam!  After participating in the MeatlyJam in 2015, I recently created an itch.io account so I could enter the CoronaDefold Jam.  I detailed the development process of Asteroid Blaster in the game devlog, which you can read here:

https://prairiewest.itch.io/asteroid-blaster/devlog/10821/day-1-exploring

Voting is on now, but after looking at the other entries I don’t think my game is going to win any prizes. No matter, it was fun to enter and interesting to blog about the whole thing.  I’m still making small changes to the game, and trying to decide if I should continue working on it, or wrap it up and move on.

Corona SDK Volume Sliders

If you are developing mobile apps with Corona SDK that use volume controls, here’s a quick tip for implementing more natural feeling controls.  Assuming that the control is a slider with values from 0 to 100, all it takes is one line of code:

volume = (math.pow(3,sliderValue/100)-1)/2

But since I really like seeing things work myself, I’ve built a very small demo project that you can download and run:
screenshot
VolumeSliders.zip

If you would like to read more on why this formula works or why it’s even needed, this page may be interesting for you: http://www.dr-lex.be/info-stuff/volumecontrols.html

Multi-language Apps with Corona SDK

Language SelectionsI was looking at the various mobile app stores and their ability to push apps out to countries all over the world and I thought that I needed to write an app that took advantage of this worldwide distribution. My reasons for doing so were two-fold: first, it was an exercise in learning, which I’m always up for; second, I thought it may actually help increase sales in foreign countries (or at least couldn’t hurt).
Continue reading