Archive for the ‘Corona’ Category

corona sdk for iphone/Android

17
Feb

To pause an audio:

audio.pause( [channel] )

To resume the audio:

audio.resume( [ { channel = c } ] )

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}  )

16
Feb

Renders the display object referenced by displayObject into a JPEG image and saves it in filename. The display object must currently be in the display hierarchy; otherwise no image is saved. If the display object is a group object, then all children are rendered. The object to be saved must be on the screen and fully within the screen boundary.

Note: When Dynamic Scaling is enabled, display.save saves the image in the device’s native resolution. For example, if this method is used to save a 100 x 200 pixel Display Object, it will be saved as a 100 x 200 image on iPhone3 but it will be a 200 x 400 image on iPhone4. (This assumes that the config.lua file specifies the content width/height as 320×480).

display.newImageRect

 should be used to load images when Dynamic Scaling is enabled, instead of display.newImage.

 

 

Syntax:

display.save( displayObject, filename [, baseDirectory] )


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

13
Feb

Syntax:

ads.show( adUnitType [, params] )