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

Corona SDK Pro Tip of the Day #14
Colors by name

Set colors by strings like 'green' or 'button'.

You can use object:setFillColor(1, 0, 0) to set red color, you can tell what color is it because you know by RGB definition (1, 0, 0) is pure red. Something harder than that will look more cryptic like object:setFillColor(0.65, 0.32, 0.47), what color is that?

Another problem with setting all the colors with numbers is that when you use the same color in different places and later you want to change it, you have to find all these places and change them manually.

It would be much easier to use something like CSS from HTML world. Define all the styles in one place and let your app use it throughout your app.

● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #12
Memory consumption

View memory consumption with a press of a single button! Or maybe two buttons...

The idea is similar to my previous pro tip. We bind one button to show current memory usage and another button to perform garbage collection.

It is useful to see if you have any memory leaks, it doesn't occupy any space on the screen or flood the terminal output with lots of messages as many other memory profiling scripts do.

● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #11
Screenshots

Easily take screenshots of your app or game with a press of a single button!

Corona now supports input from a keyboard. Let's bind "S" key to capture screenshots with display.save().

Put this code in your main.lua file.

Runtime:addEventListener('key', function (event)  
  if event.keyName == 's' and event.phase == 'down' then
    local scene = storyboard.getScene(storyboard.getCurrentSceneName())
    if scene and scene.view then
      display.save(scene.view, display.pixelWidth .. 'x' .. display.pixelHeight .. '_' .. math.floor(system.getTimer()) .. '.png')
      return true
    end
  end
end)  
● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #10
Global variables

Use a special Lua script to detect global variables.

One of the oversights of Lua language is the local keyword. Not the keyword itself, but the fact that by default all variables are created global. It should have been the other way around.

It is easier for beginners, but introduces a certain discomfort for Pro developers.

If you forget to write local in front of your variable, you can run into memory leaks or weird behaviour of your app.

● ● ●
CONTINUE READING

Corona SDK Pro Tip of the Day #8
Inline conditionals

Use "inline conditionals" for default values.

In other languages there is ternary operator ? : . which is often missed in Lua.

However Lua has an equivalent and or statement. You are advised to use it for default values in your functions.

local function newCoin(value, color, size)  
    local coin = {}
    coin.value = value or 1
    coin.color = color or 'gold'
    coin.size = size or 32
    return coin
end  
● ● ●
CONTINUE READING