shinu.s

shinu.s's page

17
Feb

For invoking a callback when audio finishes playing in Corona,

function NarrationFinished(event)

    if event.completed then
        print("Narration completed playback naturally")
    else
        print("Narration was stopped before completion")
    end
end

oldSpeech = audio.loadStream("narrationSpeech.wav")

oldSpeechChannel = audio.play( oldSpeech, { duration=30000, onComplete=NarrationFinished } )

–it will play the audio on any available channel, for at most 30 seconds, and invoke a callback when the audio finishes playing

17
Feb

For stopping an active audio channel in Corona, use the following code,

local isChannel1Active = audio.isChannelActive( 7 )
if isChannel1Active then
    audio.stop( 7 )
end

17
Feb

For playing a channel by specifying channel number in corona, use the following code,

local backgroundMusic = audio.loadStream("backgroundMusic.mp3")

backgroundMusicChannel = audio.play( backgroundMusic, { channel=7, loops=-1}  )

14
Feb

For rounding a number to its near integer in Corona,

Syntax:

local value = math.round( num )

Example:
print( math.round( 0.1 )  )     -- Output: 0.1  0
print( math.round( 0.5 )  )     -- Output: 0.5  1
print( math.round( 8.9 )  )     -- Output: 8.9  9
print( math.round( -0.1 ) )     -- Output: -0.1 0
print( math.round( -0.5 ) )     -- Output: -0.5 0
print( math.round( -8.9 ) )     -- Output: -8.9 -9

14
Feb

For returning the integral and fractional parts of a number in corona,

Syntax:

math.modf (x)

Example:
print (math.modf(5)) —- 5 0
print (math.modf(5.3)) —- 5 0.3
print (math.modf(-5.3)) —- -5 -0.3

14
Feb

For returning the maximum value of arguments in Corona,

Syntax:

math.max (x [, ...])

Example:
print (math.max(1.2, -7, 3)) —>3
print (math.max(0, -100000000)) —>0
print (math.max(0, 1/0, math.huge)) —>inf

14
Feb

For returning the minimum value of arguments in corona,

Syntax:

math.min (x [, ...])

Example:
print (math.min(1.2, -7, 3)) —> -7
print (math.min(0, 1e-9)) —> 0
print (math.min(0, 1/0, math.huge)) —> 0

23
Jan

For receiving memory warning in corona sdk use the following sample of code,

local function warningHandler( event )
    print( "memoryWarning Received!!!" )
end

Runtime:addEventListener( "memoryWarning", warningHandler )

20
Jan

For loading a scene using storyboard class in Corona SDK,

local storyboard = require "storyboard"
storyboard.gotoScene( "MenuScene" )

Here ‘MenuScene’ is the scene you want to get loaded.

20
Jan

For replicating strings in Corona SDK,

Syntax:

string.rep( s, n )
s:rep( n )

Example:

print (string.rep ("Hai ", 3))
Output- Hai Hai Hai