shinu.s

shinu.s's page

25
Apr

Use ‘audio.isChannelPlaying()’ api for checking whether an audio channel is playing in Corona.
It returns true if the specified channel is currently playing.

Syntax:

audio.isChannelPlaying( channel )

Example:

local isChannel1Playing = audio.isChannelPlaying( 1 )
if isChannel1Playing then
    audio.pause( 1 )
end

Parameters:
channel
integer: The channel you want to know is playing or not.

Returns:
True for playing, false otherwise

25
Apr

‘easing.outQuad( )’ starts motion fast and then decelerates motion to a zero velocity as it executes.

Syntax:

transition.to(displayObject, { transition=easing.outQuad})
transition.from(displayObject, { transition=easing.outQuad})
transition.dissolve(displayObject, { transition=easing.outQuad})

Example:

local currentTarget = display.newCircle(100, 100, 100)
transition.to(currentTarget, { time=400, y=300, transition=easing.outQuad})

25
Apr

When detected with a table listener within an object, each Physics preCollision event includes event.other, which contains the ID of the other Corona display object involved in the collision.

Syntax:

event.other

Example:

local physics = require("physics")
physics.start()

local crate1 = display.newImage( "crate.png" )
physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } )
crate1.myName = "first crate"

local ground = display.newImage( "ground.png" )
ground.y = display.contentHeight
ground.myName = "ground"

local function onLocalPreCollision( self, event )
        -- The preCollision  event type fires shortly before a collision occurs, so you can use this if you want
        -- to override some collisions in your game logic. For example, you might have a platform game
        -- where the character should jump "through" a platform on the way up, but land on the platform
        -- as they fall down again.

        -- Note that this event is very "noisy", since it fires whenever any objects are somewhat close!

        print( "preCollision: " .. self.myName .. " is about to collide with " .. event.other.myName )

end

-- Here we assign the above two functions to local listeners within crate1 only, using table listeners:

crate1.preCollision = onLocalPreCollision
crate1:addEventListener( "preCollision", crate1 )

25
Apr

Listener for “completion” event with “blob” key set in gameNetwork.request. Used to download blog from game network.

Syntax:

data = event.blob

Example:

local function myListener( event )
    if string.len( event.blob ) > 0
        print( "Blob received: " .. event.blob )
    else
        print( "No blob received" )
end

local gameNetwork = require "gameNetwork"

--For OpenFeint:
gameNetwork.init( "openfeint", "product-key", "secret", "display name", "appId" )

gameNetwork.request( "downloadBlob", key, myListener ) -- listener for "completion" event with "blob" key set.

09
Apr

For removing an element at a particular location from a table in Corona,

Syntax:

table.remove (t [, pos])

Example:

t = { 1,1,2,3,5,8,13 }
print (table.maxn (t))      --> 7
print (table.remove (t,4))  --> 3
print (table.maxn (t))      --> 6
print (table.remove (t))    --> 13

Parameters:
t
A table.

pos
(Optional) Position of the element to remove. Its default value is the length of the table, so table.remove(t) removes the last element of t.

Returns:
The element that was removed.

09
Apr

In order to identify which all packages are loaded, use the following code,

Syntax:

package.loaded

Example:

local ui = require("ui")
print( package.loaded.ui )       --> table: 0x170f83d0
print( package.loaded.sample )       --> nil (because 'sample' is package not loaded)
Parameters:
None.

Returns:
Table value if the package is loaded, or returns nil if the package is not loaded.

26
Mar

For putting the device to sleep when no user activity occurs like screen touch, you need to enable idle timer in Corona.
For enabling idle timer in corona, use the following code,

system.setIdleTimer( true )  -- enable (turn on) the idle timer

When active, the idle timer dims the screen and eventually puts the device to sleep when no user activity occurs (e.g. screen touches).

26
Mar

For setting the gyroscopic frequency in Corona, use the following line of code,

-- Set the measurement interval to 50 Hz.
-- This makes the system take 50 measurements per second.
system.setGyroscopeInterval( 50 )

26
Mar

For replicating a string in corona, use the following line of code:

print (string.rep ("India ", 5))

It will print:

India India India India India

21
Mar

For opening a webpage in a browser, use this Corona API,

system.openURL( "http://www.google.com" )