Archive for the ‘Corona’ Category

corona sdk for iphone/Android

14
Mar

Creates a web popup that loads a local or remote web page.

Syntax:
native.showWebPopup( url [, options] )
native.showWebPopup( x, y, width, height, url [, options] )

Example:

native.showWebPopup( 10, 10, 300, 300,
"http://www.google.com",
{urlRequest=listener} )

13
Mar

For capturing a screen in corona, you can use the following lines of code :

-- Capture Screen Function
function captureButton:tap(e)
local screenshot = display.captureScreen(true)
-- Show Image in Photo Library
media.show(media.PhotoLibrary)
end
captureButton:addEventListener("tap", captureButton)    -- Button Listener

12
Mar

The following creates a gradient object that adds horizontal/vertical linear gradients to rectangle and text objects.

local g = graphics.newGradient(
  { 255, 255, 255 },
  { 200, 200, 200 },
  "down" )

-- sets gradient 'g' on rect
local rect = display.newRect( 0, 0, 100, 200 )
rect:setFillColor( g ) 

-- sets gradient 'g' on text
local text = display.newText("Hello World!", 0, 0, native.systemFont, 16)
text:setTextColor( g )

11
Mar

To access accelerometer events in corona, you can use the following lines of code :

local shake = {}
function shake:accelerometer(e)
if(e.isShake == true) then
– do your stuff here –
print(“shaked…    “)
end
end
Runtime:addEventListener(“accelerometer”, shake)

09
Mar

We can use the the accelerometer to control the movement of images on screen. A sample code is given below:

local centerX = display.contentHeight/2
function onTilt(event)
      boat.y = centerX - (centerX * event.xGravity)
end
Runtime:addEventListener( "accelerometer", onTilt )

09
Mar
local xpos
local ypos
local lineary = {}
local linnum = 1
local function draw(e)
if(e.phase == "began")then
linnum = 1
xpos = e.x
ypos = e.y
elseif(e.phase == "moved")then
lineary[linnum] = display.newLine( xpos,ypos, e.x,e.y )
lineary[linnum]:setColor( 255, 0,0 )
lineary[linnum].width = 3
linnum = linnum+1
xpos =e.x
ypos = e.y
elseif(e.phase == "ended" )then
for i = 1,linnum-1 do
lineary[i]:removeSelf()
end

end

end

Runtime:addEventListener("touch",draw)

07
Mar
Description:

Resumes a timer that was paused with timer.pause.

Syntax:
result = timer.resume( timerId )
Example:
local function listener( event )
    print( "listener called" )
 end

timer1 = timer.performWithDelay( 2000, listener )  -- wait 2 seconds
...
result = timer.pause( timer1 )
print( "Time remaining is " .. result )
...
result = timer.resume( timer1 )
print( "Fire time is " .. result )

06
Mar
local socket = require("socket")
 

–Connect to the client

local client = socket.connect("www.google.com",  80)
--Get IP and Port from client
local ip, port = client:getsockname()

–Print the ip address and port to the terminal

print("IP Address: " .. ip)
print("Port: " .. port)

, , , , , ,

05
Mar

We  can use two dimensional array in corona. Here is an example of how to use it.

local cols = 10

local rows = 10

local grid = { }---1D array

for i=1,cols do

grid[i] = { }

for j=1,rows do

grid[i][j] = { x=i*20,y=j*20,width=20,height=20,index=i+j }----2D array

end

end

03
Mar
file:write( arg1 [, arg2] [, ...] )

Writes the value of each of its arguments to the file. The arguments must be strings or numbers.
To write other values, use tostring or string.format before write.

,