Corona SDK Pro Tip of the Day #25
Finalize event

Finalize event is extremely useful for developing. If you are familiar with C++ or other classic OOP languages, you can think about finalize event as a destructor - something that happens when a Corona Display Object is destroyed.

I use it all the time. Mostly for cancelling transitions or timers that a particular object uses.

local circle = display.newCircle(group, 100, 100, 10)

function circle:animate()  
    self.t = transition.to(self, {time = 1000, alpha = 0})
end

function circle:finalize()  
    -- This is called on circle:removeSelf() or display.remove(circle)
    if self.t then
        transition.cancel(self.t)
    end
end

circle:addEventListener('finalize')  
● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #24
Changing FPS dynamically

Did you know that you can invoke almost any arbitrary code inside config.lua? We can use it to read a txt file and set fps according to it's content. That way users can switch fps from in game settings.

Here is such config.lua

local fps = 60  
local path = system.pathForFile('fps.txt', system.DocumentsDirectory)  
local file = io.open(path, 'r')  
if file then  
    local content = file:read('*a')
    if content == '30' then
        fps = 30
    elseif content == '60' then
        fps = 60
    end
    io.close(file)
end

application = {  
    content = {
        width = 320,
        height = 480,
        scale = 'letterbox',
        fps = fps,
        imageSuffix = {
            ['@2x'] = 1.2
        }
    }
}
● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #22
Remote console

Send print output and runtime errors from a device via network to your computer for debugging.

When you are using the Simulator it's easy to see all the error messages and print output in it's console. However on a device we have to use either Xcode Organizer for iOS or adb logcat for Android.

Fear no more! Here comes remote console script that allows you to receive all the info you need directly from your device with no hassle.

● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #19
Music file formats

Did you know that using MP3 files is not free? While I haven't heard of any lawsuits against people who use it and don't pay, however it's nice to be on the safe side.

According to http://mp3licensing.com/royalty/games.html you have to pay at least $2,500 per game if you have more than 5000 downloads.

Use OGG and M4A file formats instead. One drawback is that you can't use one of them on both Android and iOS. You have to use OGG on Android and M4A on iOS.

Again from my app.lua.

local ext = (_M.isAndroid or _M.isSimulator) and '.ogg' or '.m4a'

local sounds = {  
    music = 'sounds/music' .. ext
}

I define file extension according to the current platform and load corresponding music file.

I have to maintain music files before building for the stores, but if you are too lazy, you can keep both version.

CONTINUE READING

Corona SDK Pro Tip of the Day #16
Touch blocking

Use a helper function to quickly block touches for an object.

Often you need to stop touch or tap events, for example for a popup window. Ideally you need to block both of them and also account for invisible objects.

Here is my helper function.

local _M = {}

local function rt() return true end  
function _M.returnTrue(obj)  
    if obj then
        obj:addEventListener('touch', rt)
        obj:addEventListener('tap', rt)
        obj.isHitTestable = true
    else
        return rt
    end
end

return _M  
● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #15
Automatic image downsizing

Use a special script to make lower res image versions. @4x -> @2x -> 1x version.

It takes time to manually save scaled down versions of your original artwork. If you support iPad retina, your original is @4x version, otherwise it's @2x version.

So I've made a script that uses bash and ImageMagick to find and scale down all high res versions into lower res versions.

Grab it here.

● ● ●
CONTINUE READING