Archive for the ‘Corona’ Category

corona sdk for iphone/Android

13
Apr
Syntax:
os.difftime( t1, t2 )
Example:
local t1 = os.time()

-- Print the elasped time
local function dspTime()
        print( "Time elasped = " .. os.difftime( os.time(), t1) )
end

timer.performWithDelay( 2000, dspTime )  -- wait 2 second before calling function

13
Apr
Syntax:
table.concat (table [, sep [, i [, j]]])
Example:

 

t = { 1, 2, "three", 4, "five" }
print (table.concat(t))              --> 12three4five
print (table.concat(t, ", "))        --> 1, 2, three, 4, five
print (table.concat(t, ", ", 2, 4))  --> 2, three, 4

12
Apr

 

Syntax :.

math.deg (x)

Example :

print(math.deg(180))              -->   3.1415926535898

print(math.deg(math.pi))       --> 180

print(math.deg(math.pi/2))   --> 90

11
Apr

Description:
A boolean for whether the rotation of the body should be locked, even if the body is under load or subjected to off-center forces. The default is false.

Syntax:

body.isFixedRotation

Example:

myBody.isFixedRotation = true
local state = myBody.isFixedRotation

11
Apr

Syntax:  

object = display.captureScreen( saveToAlbum )

Calling this method displays the captured image on the screen on top of all other display objects. Use

object:removeSelf()

 
to remove this object from the screen.

Screen capture only works for openGL content and not for any of the native display objects.

eg:

local rect = display.newRect(0, 0, display.contentWidth, display.contentHeight)
rect:setFillColor(0, 255, 0) 

local circle = display.newCircle(155, 100, 36)
circle:setFillColor(255, 0, 0) 

-- Capture the screen
local screenCap = display.captureScreen( true )

-- Remove the objects from the screen
rect:removeSelf()
circle:removeSelf()

-- Scale the screen capture, now on the screen, to half it's size
screenCap:scale(.5,.5)

local alert = native.showAlert( "Success", "Screen Capture Saved to Library", { "OK" } )

, ,

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.

05
Apr

Description:
Associates a mask with a display object. To remove an object’s mask, use object:setMask(nil). We can modify a display object’s mask’s x and y position, x-scale and y-scale factors, and rotation

Syntax:

object:setMask( mask )

05
Apr

Description:
Returns information about the system on which the application is running.

Syntax:

system.getInfo( parm )

Example:

print( system.getInfo( "deviceID" ) )  -- display the deviceID

Parameters:
parm

The first argument param is a string that determines what is returned.

Valid values for param:

“name” returns the human readable model name. On iPhone, this would be the name of the phone as it appears in iTunes, e.g. “Steve’s iPhone”.

“model” returns the device model (as specified by the manufacturer). These include:

“iPhone”
“iPad”
“iPhone Simulator”
“iPad Simulator”
“Nexus One”
“Droid”
“Galaxy Tab”
Note: The above is a list of all the iOS models and the Android devices used in the Corona Simulator. Most Android devices return a model number instead of a model name.

“deviceID” returns the unique id of the device, e.g. IMEI or similar number.

“environment” returns the environment that the app is running in. These include:

“simulator” the Corona Simulator
“device” iOS, Android device and Xcode Simulator
“platformName” returns the platform name (the OS name), i.e. one of the following:

“Mac OS X” (Corona Simulator on Mac)
“Win” (Corona Simulator on Windows)
“iPhone OS” (all iOS devices and Xcode Simulator)
“Android” (all Android devices)
“platformVersion” returns a string representation of the platform version. This is sometimes, but not always, a number — for example a Droid X is currently returning “2.1-update1″.

“version” This is deprecated. Use “build” instead to distinguish between different Corona build versions.

“build” returns the Corona build string as it appears in the About box of the Corona Simulator.

“textureMemoryUsed” returns the texture memory usage (in bytes). Texture memory (for graphics/images) tends to be the most sharply limited resource in mobile development, since it runs out before normal memory.

“maxTextureSize” returns the maximum texture width or height supported by the device. (Available starting from Build 2011.310)

“architectureInfo” returns a string describing the underlying CPU architecture of the device you are running on. This API is mostly for internal debugging but may have uses. Strings may be subject to changes in the future depending on the changing landscape of devices and CPUs. (Available starting from Build 2011.326).

Android on ARM devices will return “ARM” (typically for ARMv6) or “ARM Neon” (ARMv7). iOS will return values such as: “iPhone1,1″, “iPhone1,2″, where mappings are:

“iPhone1,1″ = iPhone 1G
“iPhone1,2″ = iPhone 3G
“iPhone2,1″ = iPhone 3GS
“iPod1,1″ = iPod touch 1G
“iPod2,1″ = iPod touch 2G
Mac may return i386, x86_64, ppc, or ppc64. (Currently only i386 is available.)
Windows is currently unsupported.

Returns:
String of parameter requested.

Remarks:
“maxTextureSize” available in Build 2011.310
“architectureInfo” available in Build 2011.326

Supported on operating systems and platforms for build numbers shown:
Mac OS X:Corona SDK 2.0
Windows: Corona SDK 2.0
iOS: Corona SDK 2.0
Android: Corona SDK 2.0

04
Apr
Description:

Used with

system.pathForFile

to create a path for storing and retrieving files that only need to persist while the application is running. The path is “/tmp”.

This property can also be used with other APIs requesting a “baseDirectory” as a parameter (e.g.,display.newImage, display.save, media.playSound.)

On the Corona Simulator this will be in a sandboxed folder on a per-application basis. You can view the directories and the files by clicking on “Show Project Sandbox” in the Simulator.

Note: This directory may not exist after the application exits.

Syntax:
path = system.pathForFile( filename, system.TemporaryDirectory )
Example:
local path = system.pathForFile( "data.txt", system.TemporaryDirectory )

-- io.open opens a file at path. returns nil if no file found
local fh, reason = io.open( path, "r" )

if fh then
   -- read all contents of file into a string
   local contents = fh:read( "*a" )
   print( "Contents of " .. path .. "\n" .. contents )
else
   print( "Reason open failed: " .. reason )  -- display failure message in terminal

   -- create file because it doesn't exist yet
   fh = io.open( path, "w" )

   if fh then
        print( "Created file" )
   else
        print( "Create file failed!" )
   end

   local numbers = {1,2,3,4,5,6,7,8,9}
   fh:write( "Feed me data!\n", numbers[1], numbers[2], "\n" )

   for _,v in ipairs( numbers ) do
       fh:write( v, " " )
   end

   fh:write( "\nNo more data\n" )
end

io.close( fh )