Upload
ivan-palomino-taype
View
251
Download
0
Embed Size (px)
Citation preview
8/18/2019 Manual Corona SDK v1
1/18
REFERENTE A LUA
PALABRAS RESERVADAS
and break do else elseif end false
for function if in local nil not
or repeat return then true until while
SIMBOLOS RESERVADOS
+ - * / % ^ #
== ~= = < > =
( ) { } [
! " $ $$ $$$
TABLAS
t = {} --create a tale
& = ''
t[& = $ --new tale entr, with &e,='' an .alue=$
print( t[& ) --> $
print( t['' ) --> $
print( t$ ) --> $
t[ = 'foo' --new tale entr, with &e,= an .alue='foo'
print( t[ ) --> 'foo'
Campos de tabla
t = { foo='hello' } --create tale with a 0in1le propert, 'foo'
print( t$foo ) --> 'hello'
t$foo = ',e' --a00i1n a new .alue to propert, 'foo'
print( t$foo ) --> ',e'
t$ar = 2 --create a new propert, na3e 'ar'
print( t$ar ) --> 2
print( t['ar' ) --> 2
VARIABLE GLOBAL (solo si es e!esa"io# print( 0 ) --> nil
0 = '4ne 3illion ollar0'
print( 0 ) --> 4ne 3illion ollar0
VARIABLE LOCAL ("e!omedado#
local , = 2 --local .ariale
8/18/2019 Manual Corona SDK v1
2/18
OPERADORES ARITMETICOS
+ (addition) - (subtraction)
* (multiplication) / (division)
% (modulo) ^ (exponentiation)
OERADORES RELACIONALES
== (equal to)
~= (not equal to)
< (less than)
(!reater than)
8/18/2019 Manual Corona SDK v1
3/18
REFERENTE A CORONA
IMPRIMIR .-ELLO ,ORLD/ EN CONSOLA
print( ello ,orld )
MOSTRAR .-ELLO ,ORLD / EN PANTALLA
'.012.'& displa#ne30ext( strin!4 x4 #4 "ont4 si5e )
67689:$& local m#0ext$bect = displa#ne30ext( ello ,orld4 ;4 >?4
1rial4 )
860$@$ 911 9$6:6 A$:$
m#0ext$bect&setBillAolor( r4 !4 b )
59:6;54 ?;64
--para 8ue el teto en pantalla ca3ie e color aleatoria3ente
"unction screen0ap()
local r = mathrandom( 4 ; )
local ! = mathrandom( 4 ; )
local b = mathrandom( 4 ; )
m#0ext$bect&setBillAolor( r/;4 !/;4 b/; )
end
--a1re1ano li0tener (o,ente e0cuhaor) para 8ue caa .e@ 8ue 0e hace clic&
--en el 3i03o punto 0e ca3ie e color el tecto en pantalla
displa#current'ta!e&add6vent:istener( tap4 screen0ap )
--A0 el e8ui.alente a e0to (li0tener 1loal)
untime&add6vent:istener(tap4 screen0ap)
--ta3iBn 0e puee poner un li0tener 0olo para 3o0trar el ca3io e color
--cuano 0olo 0e toca el teto en pantalla
m#0ext$bect&add6vent:istener(tap4 screen0ap)
FISICA (b0si!a#
local ph,0ic0 = re8uire( 'ph,0ic0' )
ph,0ic0$0tart()
OB*ETOS VISUALES
e1Ima)e2 &o"ma 3
C6D5E6C" i0pla,$new63a1e( 'ruta', )
local 0&, = i0pla,$new63a1e( '&1Fclou0$pn1' )
0&,$ = G2! 0&,$, = HI -- (propieae0 el oJeto para ca3iar 0u po0icion)
e1Ima)e2 &o"ma 4
local 0&, = i0pla,$new63a1e( '&1Fclou0$pn1'G2HI )
A)"e)ado &5si!a al !'e"po del ob6eto
ph#sicsaddCod#(sD#4 static4 E densit#=F4 "riction=G4 bounce=F H )
OPTIMI7ACION
8/18/2019 Manual Corona SDK v1
4/18
Apa)a" )ps8 1i98 a!ele"met"o8 et! po":'e !os'me la bate"5a
Usa" memo"ia pote!ia de 4 !'ado se 'sa )"a9!os8 el !omado0,0te3$1et6nfo()te pe"mite sabe" los datos del dispositi;o
Pa"a l'a< es me6o" 'sa"
Ubi!a!i8 'sa" ;a"iable lo!al .CC+/
--4-:4;5: (6C;4?K5LA = no
reco3enao)
;;E = i0pla,$content;enterE
--1loal .ariale
for i = 22 o
local i3a1e = i0pla,$new63a1e(
'3,63a1e' )
i3a1e$ = ;;E
en
--:4;5: (KA;4MMAA)
local ;;E = i0pla,$content;enterE
--local .ariale
for i = 22 o
local i3a1e = i0pla,$new63a1e(
'3,63a1e' )
i3a1e$ = ;;E
en
tambie apli!a a la lib"e"5a matem0ti!a
--4-:4;5: (6C;4?K5LA)
;;E = i0pla,$content;enterE
--1loal .ariale
for i = 22 o
local i3a1e = i0pla,$new63a1e(
'3,63a1e' )
i3a1e$ = ;;Een
--'AEDAK5:' :4;5: (KA;4MMAA)
local 0in = 3ath$0in --local
reference to N3ath$0inN
local function foo()
for i = 22 o
= + 0in(i)
en return
en
= a &'!ioes> ;e" o"de de !"ea!i de &'!ioes tambi?
--4-:4;5: (6C;4?K5LA)
function func()
func( '3,Oalue' )
en
function func( , )
print( , )
en
func()
--:4;5: (KA;4MMAA)
local function func( , ) --NfuncN
properl, 0cope ao.e NfuncN
print( , )
en
local function func()
func( '3,Oalue' )
en
func()
Pa"a poe" elemetos e las tablas .e;ita" table@ise"t(# .
--tableinsert() (@.'A$I1J6@) --:$$9 .@62 860$@ (6A$886@6@)
http://docs.coronalabs.com/api/library/system/getInfo.htmlhttp://docs.coronalabs.com/api/library/system/getInfo.html
8/18/2019 Manual Corona SDK v1
5/18
local a = EH
local tableKinsert = tableinsert
"or i = ;4; do
tableKinsert( a4 i )
end
local a = EH
"or i = ;4; do
aLiM = i
end
--01C:6 '.N6 860$@ (1AA6901C:6)
local a = EH
"or i = ;4; do
aLOa+;M = i
end
--A$I06 860$@ (6A$886@6@)
local a = EH
local index = ;
"or i = ;4; do
aLindexM = i
index = index+;
end
Pa"a sa!a" elemetos de las tablas e;ita" . table@'pa!(# .
--unpacD() (@.'A$I1J6@)
local a = E ;4 >4 F4 ? H
"or i = ;4; do
print( unpacD(a) )
end
--:$$9 860$@ (6A$886@6@)
local a = E ;4 >4 F4 ? H
"or i = ;4; do
print( aL;M4aL>M4aLFM4aL?M )
end
E;ita" ipai"s(#
--ipairs() (@.'A$I1J6@)
local t; = EH
local t> = EH
local tF = EH
local t? = EH
local a = E t;4 t>4 tF4 t? H
"or i4v in ipairs( a ) do
print( i4v )
end
--:I1 A$'0IA0 (6A$886@6@)
local t; = EH
local t> = EH
local tF = EH
local t? = EH
local a = E t;4 t>4 tF4 t? H
"or i = ;4Oa do
print( aLiM )
end
Me6o"amieto de la matem0ti!a
[email protected].'.$ (@.'A$I1J6@)
x/> Q #/R
--8I:0.9:.A10.$ CS @6A.81:
(6A$886@6@)
x * G Q # * ;>G
--629$60.10.$ (@.'A$I1J6@)
x^F
--8I:0.9:.A10.$ (6A$886@6@)
x * x * x
Tambie e el "esto po" di;isi ie%a!ta
--math"mod() (@.'A$I1J6@)
local "mod = math"mod
"or i = ;4; do
i" ( "mod( i4F ) < ; ) then
--8$@I:I' $9610$ (6A$886@6@)
"or i = ;4; do
i" ( ( i%F ) < ; ) then
local x = ;
http://docs.coronalabs.com/guide/basics/optimization/index.html#TOChttp://docs.coronalabs.com/guide/basics/optimization/index.html#TOC
8/18/2019 Manual Corona SDK v1
6/18
local x = ;
end
end
end
end
ADMINISTRACION DE AUDIO
Pa"a soidos !o"tos 'sa" .loadSo'd/
local sound0able = E
m#'ound; = audioload'ound( a3av )4
m#'ound> = audioload'ound( b3av )4
m#'oundF = audioload'ound( c3av )4
m#'ound? = audioload'ound( d3av )4
m#'oundG = audioload'ound( e3av )4
m#'ound = audioload'ound( "3av )4
m#'oundT = audioload'ound( !3av )4
m#'oundR = audioload'ound( h3av )4H
--S lue!o los llamas
local m#'ound = audiopla#( sound0ableLm#'ound;M )
--# para meorar el rendimiento de liberaciUn de memoria se elimina asi
local '0 = sound0able
"or s=O'04;4-; do
audiodispose( '0LsM ) Q '0LsM = nilend
GRAFICOS8 AUDIO ANIMACION
si)i9!a :'e a= mas do!'meta!i
'intaxis
0anto x4 # representan posiciUn
6emplo
displa#ne3Jroup() local rect = displa#ne3ect(4 4 ;4 ;)
rect&setBillAolor( G )
local !roup = displa#ne3Jroup()
!roup&insert( rect )
displa#ne3.ma!e( Lparent4M "ilename
L4base@irM L4x4#M L4isBullesolutionM)
local m#.ma!e = displa#ne3.ma!e( ima!epn! )
--al!unos mVtodos (aplica para todos los obetos)
-- position the ima!e
m#.ma!e&translate( ;4 ; )
-- tint the ima!e red
m#.ma!e&setBillAolor( ;4 4 )-- remove the ima!e
8/18/2019 Manual Corona SDK v1
7/18
m#.ma!e&remove'el"()
m#.ma!e = nil
--al!unas propiedades (aplica para todos los obetos)
-- hide the ima!em#.ma!eisPisible = "alse
displa#ne3.ma!e( Lparent4M
ima!e'heet4 "rame.ndex )
-- "irst4 create the ima!e sheet obect
local options =
E
-- 0he params belo3 are required
3idth = T4
hei!ht = ?;4
numBrames = >4
-- 0he params belo3 are optional (used "or d#namicima!e sheet selection)
sheetAontent,idth = T4 -- 3idth o" ori!inal ;x si5e
o" entire sheet
sheetAontentei!ht = R> -- hei!ht o" ori!inal ;x
si5e o" entire sheet
H
local ima!e'heet = !raphicsne3.ma!e'heet( "ishiespn!4
options )
local m#.ma!e = displa#ne3.ma!e( ima!e'heet4 ; )
displa#ne3.ma!eect( LparentJroup4M
"ilename4 Lbase@ir4M 3idth4 hei!ht )
local ima!e = displa#ne3.ma!eect( ima!epn!4 ;4 ;
)
--al!unas propiedades (aplica para todos los obetos)
ima!ex = displa#contentAenter2
ima!e# = displa#contentAenterS
-- hide the obect
ima!eisPisible = "alse
--al!unos mVtodos (aplica para todos los obetos)-- remove it
ima!e&remove'el"()
ima!e = nil
displa#ne3.ma!eect( LparentJroup4M
ima!e'heet4 "rame.ndex4 3idth4
hei!ht )
-- "irst4 create the ima!e sheet obect
local options =
E
-- 0he params belo3 are required
3idth = T4
hei!ht = ?;4
numBrames = >4
8/18/2019 Manual Corona SDK v1
8/18
-- 0he params belo3 are optional (used "or d#namic
ima!e sheet selection)
sheetAontent,idth = T4 -- 3idth o" ori!inal ;x si5e
o" entire sheet
sheetAontentei!ht = R> -- hei!ht o" ori!inal ;xsi5e o" entire sheet
H
local ima!e'heet = !raphicsne3.ma!e'heet( "ishiespn!4
options )
-- create ne3 ima!e "rom the above ima!e sheet
local ob = displa#ne3.ma!eect( ima!e'heet4 ;4 T4 ?; )
obx4 ob# = ;4 ;
displa#ne30ext( LparentJroup4M text4x4 #4 "ont4 "ont'i5e )
displa#ne30ext( LparentJroup4M text4
x4 #4 L3idth4 hei!ht4M "ont4
"ont'i5e )
*local m#0ext = displa#ne30ext( ello ,orld4 ;4 >4
natives#stemBont4 ; )
--al!unos mVtodos (aplica para todos los obetos)
m#0ext&setBillAolor( ;4 4 )
'prite 8Vtodo corona
'e obviara la sintaxis
*
-- primero creamos las opciones de hoa
local sheet$ptions =
E
3idth = G;>4
hei!ht = >G4 numBrames = R
H
-- lue!o car!amos la ima!en sprite
local sheetKrunnin!Aat =
!raphicsne3.ma!e'heet( sritepumapn!4 sheet$ptions )
-- acto se!uido creamos la secuencia
local sequencesKrunnin!Aat = E
-- "irst sequence (consecutive "rames)
E
name = normalun4 start = ;4
count = R4
time = R4
loopAount = ?
H
H
-- despuVs creamos el sprite
local runnin!Aat = displa#ne3'prite( sheetKrunnin!Aat4
sequencesKrunnin!Aat )
--"inalmente usamos sus mVtodos
runnin!Aat&translate(;4;) --opcionalrunnin!Aat&pla#()
8/18/2019 Manual Corona SDK v1
9/18
'prite mVtodo texture pacDer
'e obviara la sintaxis
* loop@irection ("or3ard # bounce ) en sequence@ata
-- usa un archivolua !enerado por texture pacDer
-- primero llamamos al archivo lua
local sheet.n"o = require(spritesheet)4 este contiene
las opciones de hoa # otros > metodos
--lue!o car!amos la ima!en spritelocal mi'prite =
!raphicsne3.ma!e'heet(spritesheetpn!4
sheet.n"o&!et'heet())
--despues creamos la secuencia
local sequence@ata = E
E
name=3alD4 -- name o" the animation
sheet=mi'prite4 -- the ima!e sheet
start=sheet.n"o&!etBrame.ndex(;)4 -- "irst "rame
count=R4 -- number o" "rames
time=;4 -- speed loopAount=? -- repeat
H
H
--"inalmente creamos el sprite
sprite = displa#ne3'prite( mi'prite4 sequence@ata )
sprite&set'equence(3alD)
---# le damos pla#
sprite&pla#()
---- tambiVn podemos obtener cualquier ima!en de la hoa
--sprite asidispla#ne3.ma!e(mi'prite4
sheet.n"o&!etBrame.ndex(;))
displa#ne3ect( x4 #4 3idth4 hei!ht )
displa#ne3ect( parent4 x4 #4 3idth4
hei!ht )
* propiedades x;4x>4xF4x?
--eemplo
local m#ectan!le = displa#ne3ect( 4 4 ;G4 G )
--aplicando propiedades # metodos
m#ectan!lestroDe,idth = F
m#ectan!le&setBillAolor( G )
m#ectan!le&set'troDeAolor( ;4 4 )
displa#ne3Aircle( xAenter4 #Aenter4
radius )displa#ne3Aircle( parent4 xAenter4
#Aenter4 radius )
-- eemplo con sus propiedades # metodos
local m#Aircle = displa#ne3Aircle( ;4 ;4 F )m#Aircle&setBillAolor( G )
m#AirclestroDe,idth = G
m#Aircle&set'troDeAolor( ;4 4 )
displa#ne3oundedect( x4 #4 3idth4
hei!ht4 corneradius )
displa#ne3oundedect( parent4 x4 #4
3idth4 hei!ht4 corneradius )
-- eemplo con sus propiedades # metodos
local m#oundedect = displa#ne3oundedect( 4 4 ;G4
G4 ;> )
m#oundedectstroDe,idth = F
m#oundedect&setBillAolor( G )
m#oundedect&set'troDeAolor( ;4 4 )
displa#ne3:ine( LparentJroup4M x;4#;4 x>4 #> L4 xF4 #F4 M )
local star = displa#ne3:ine( >4 W4 >>T4 ;G )star&append( FG4;G4 >?F4>;4 >G4>W4 >4>?G4 ;FG4>W4
8/18/2019 Manual Corona SDK v1
10/18
-- solo los dos primeros pares son
necesarios
;GT4>;G4 WG4;G4 ;TF4;G4 >4W )
star&set'troDeAolor( ;4 4 4 ; )
starstroDe,idth = R
displa#ne39ol#!on( x4 #4 vertices )
displa#ne39ol#!on( parent4 x4 #4vertices )
local hal", = displa#content,idth * G
local hal" = displa#contentei!ht * G
local vertices = E 4-;;4 >T4-FG4 ;G4-FG4 ?F4;4 G4W4
4?G4 -G4W4 -?F4;G4 -;G4-FG4 ->T4-FG4 H
local o = displa#ne39ol#!on( hal",4 hal"4 vertices )
o"ill = E t#pe=ima!e4 "ilename=mountainspn! H
ostroDe,idth = ;
o&set'troDeAolor( ;4 4 )
displa#ne36mbossed0ext( LparentJroup4
M text4 x4 #4 "ont4 "ont'i5e )
displa#ne36mbossed0ext( LparentJroup4M text4 x4 #4 L3idth4 hei!ht4M "ont4
"ont'i5e )
local m#0ext = displa#ne36mbossed0ext( hello4 >4
;4 natives#stemBont4 ? )
m#0ext&setBillAolor( G )m#0ext&set0ext( ello ,orld )
local color =
E
hi!hli!ht = E r=;4 !=;4 b=; H4
shado3 = E r=F4 !=F4 b=F H
H
m#0ext&set6mbossAolor( color )
displa#ne3Aontainer( Lparent4 M
3idth4 hei!ht )
-- Areate a container
local container = displa#ne3Aontainer( ;>R4 ;>R )
-- Areate an ima!e
local bD!d =
displa#ne3.ma!e( aquariumbacD!round.9honep! )
-- .nsert the ima!e into the container
container&insert( bD!d4 true )
-- Aenter the container in the displa# area
container&translate( displa#content,idth*G4
displa#contentei!ht*G )
-- 0ransition (rotate) the container
transitionto( container4 E rotation=F4transition=easin!in$ut6xpoH )
displa#ne3'napshot( 34 h )
displa#ne3'napshot( parent4 34 h )
local snapshot = displa#ne3'napshot( >4 > )
mathrandomseed( ) X random se palica solo ; ve5
-- 1dd "ish to the screen
"or i=;4? do
local "ish = displa#ne3.ma!e( "ishsmallredpn! )
-- move to random position in a >x> re!ion in the
middle o" the screen
"ish&translate( mathrandom( -;4 ; )4mathrandom( -;4 ; ) )
8/18/2019 Manual Corona SDK v1
11/18
-- insert "ish into snapshot
snapshot!roup&insert( "ish )
end
snapshot&translate(;4 >?) -- Aenter snapshotsnapshot&invalidate() -- .nvalidate snapshot
snapshotalpha = G -- 1ppl# to "lattened ima!e
68.'$ @6 910.AI:1' (BI6J$)
Isar archivo son4 ahY es donde se
hacen las modi"icaciones
-- equire the 7'$ librar# "or decodin! purposes
local son = require son
-- ead the exported 9article @esi!ner "ile (7'$) into a
strin!
local "ile9ath = s#stempathBorBile( "ireson )
local " = ioopen( "ile9ath4 r )
local "ile@ata = "&read( *a )
"&close()
-- @ecode the strin!
local emitter9arams = sondecode( "ile@ata )
-- Areate the emitter 3ith the decoded parameters
local emitter; = displa#ne36mitter( emitter9arams )
-- Aenter the emitter 3ithin the content area
emitter;x = displa#contentAenter2
emitter;# = displa#contentAenterS
PROPIEDADES METODOS COMUNES
PROPIEDADES METODOS p"opiedad alpa (poe" t"aspa"e!ia#
local obect = displa#ne3.ma!e( ima!epn! )
obectalpha = TG -- set to TG% opacit#
metodo !oteToLo!al
-- Kectan1le that fill0 0creen
local rect = i0pla,$newKect( 2 2
i0pla,$contentPith i0pla,$contentQei1ht )
rect$ = i0pla,$content;enterE ! rect$, =
i0pla,$content;enterR
rect$0tro&ePith = ! rect"0etCtro&e;olor( 2 2 )
rect"0etill;olor( 2 2 2 )
-- ;reate tet oJect0 to i0pla, content an
local coorinate0
local contentDet = i0pla,$newDet( '' 2 2
i0pla,$nati.eC,0te3ont G )
local localDet = i0pla,$newDet( '' 2 2
i0pla,$nati.eC,0te3ont G )
localDet$anchorE = 2 ! localDet$anchorR = 2
contentDet$anchorE = 2 ! contentDet$anchorR =
2
8/18/2019 Manual Corona SDK v1
12/18
function 0how;oorinate0( e.ent )
-- Let an , of touch e.ent in content
coorinate0
local contentE contentR = e.ent$ e.ent$,
-- ;on.ert to local coorinate0 oflocal localE localR =
e.ent$tar1et"contentDo:ocal( contentE contentR
)
-- i0pla, content an local coorinate
.alue0
contentDet$tet = ';4DAD" ' $$
to0trin1(contentE) $$ ' ' $$
to0trin1(contentR)
localDet$tet = ':4;5:" ' $$
to0trin1(localE) $$ ' ' $$ to0trin1(localR) contentDet$ contentDet$, = e.ent$+2
e.ent$,
localDet$ localDet$, = e.ent$+2
e.ent$,+2
localDet$anchorE = 2 ! localDet$anchorR =
2
contentDet$anchorE = 2 !
contentDet$anchorR = 2
return true
en
rect"aA.ent:i0tener( 'touch' 0how;oorinate0
)
p"opiedad a!o" (!ambia" !et"o dedib'6o#
local rect> = displa#ne3ect( 4 4 G4 G )
rect>anchor2 = (4 G U ;)
rect>anchorS = (4 G U ;)
M?todo lo!alToCotet
-- ;reate a 08uare
local 08uare = i0pla,$newKect( 22 22 2
2 )
08uare"0etill;olor( )
-- ;reate another 08uare on top an rotate it
2 e1ree0
local reC8uare = i0pla,$newKect( 22 222 2 )
reC8uare"0etill;olor( 2 2 2$G )
reC8uare$rotation = 2
local 08;enterE 08;enterR =
08uare"localDo;ontent( 2 2 )
print( 'Phite 08uareN0 center po0ition in
0creen coorinate0" ' 08;enterE 08;enterR )
-- Let the content po0ition of the white
08uareN0 top-left corner-- ?0in1 ( -2-2 ) 0pecifie0 the top left
8/18/2019 Manual Corona SDK v1
13/18
corner of the 08uare 0ince itN0 22 in 0i@e
local whiteD:E whiteD:R =
08uare"localDo;ontent( -2 -2 )
print( 'Phite 08uareN0 top-left po0ition in
0creen coorinate0" ' whiteD:E whiteD:R )
-- Let the content po0ition of the re 08uareN0
top-left corner inepenent of it0 rotation
-- ?0in1 ( -2-2 ) 0pecifie0 the top left
corner of the 08uare 0ince itN0 22 in 0i@e
local reD:E reD:R =
reC8uare"localDo;ontent( -2 -2 )
print( 'Ke 08uareN0 top-left po0ition in
0creen coorinate0" ' reD:E reD:R )
p"opiedad !otetBo'd (obtee"l5mites del ob6eto#
local rect = displa#ne3ect( ;4 ;4 G4G )
local bounds = rectcontentCounds
print( x8in& boundsx8in ) -- x8in& ;
print( #8in& bounds#8in ) -- #8in& ;
print( x8ax& boundsx8ax ) -- x8ax& ;G
print( #8ax& bounds#8ax ) -- #8ax& ;G
!"eado = bo""ado 'a ima)e !obotoes
local function iuJar;arro( e.ent ) if e.ent$pha0e == 'ene' then
oJ =
i0pla,$new63a1eKect( 'carro$pn1' 2222 )
oJ"tran0late( 22 22 )
en
en
local function orra;arro( e.ent )
--oJ =
i0pla,$new63a1eKect( 'carro$pn1' 2222 )
--oJ"tran0late( I2 22 )--i0pla,$newDet('lo creo' 22 I2
arial 2)
if e.ent$pha0e == 'ene' then
oJ"re3o.eCelf()
oJ = nil
contaor=contaor+2
i0pla,$newDet('lo orro'
22 22+contaor arial 2)
en
en
local 1rupoSotoniuJar = i0pla,$newLroup()
local otoniuJar =
i0pla,$newKouneKect( 1rupoSotoniuJar22
I2 I2 2 )
local tetoiuJar =
i0pla,$newDet( 1rupoSotoniuJar '6S?T5K'
2 2 5K65: 2 )
tetoiuJar"0etill;olor( 2 )
1rupoSotoniuJar"tran0late(UI22)
8/18/2019 Manual Corona SDK v1
14/18
local 1rupoSotonSorrar = i0pla,$newLroup()
local otonSorrar =
i0pla,$newKouneKect( 1rupoSotonSorrar22
I2 I2 2 )
local tetoSorrar =
i0pla,$newDet( 1rupoSotonSorrar 'S4KK5K' 22 5K65: 2 )
tetoSorrar"0etill;olor(2)
1rupoSotonSorrar"tran0late(I22)
otoniuJar"aA.ent:i0tener('touch'
iuJar;arro)
otonSorrar"aA.ent:i0tener('touch'
orra;arro)
p"opiedad "otatio ("ota" ' ob6eto#
local rect = displa#ne3ect( ;4 ;4 G4
G )rectrotation = GG -- a"ecta el tamaZo
print( contentei!ht& rectcontentei!ht )
print( content,idth& rectcontent,idth )
"otado 'a "e!ta
local rect = displa#ne3ect( G4 G4 ;4
> )rect&setBillAolor( ;4 4 )
-- otate the rectan!le ?G de!rees
rect&rotate( ?G )
p"opiedad ei)t8 1idt (obtee"medida#
local rect = displa#ne3ect( ;4 ;4 G4
G )
rect&scale(>4>) X no a"ecta al tamaZo
print( ei!ht& recthei!ht )
print( ,idth& rect3idth )
Es!alado 'a ima)e
local star = displa#ne3.ma!e( starpn! )
-- 'cale the ima!e b# >% (x) and G% (#)
star&scale( >4 G )
p"opiedad masS!ale (!ambia"tamao de 'a mas!a"a#
-- ;rea la i3a1en
local i3a1e =
i0pla,$new63a1eKect( 'cuarao$Jp1' 22
I2 )
i3a1e"tran0late( i0pla,$content;enterE
i0pla,$content;enterR )
-- crea la 3a0cara , la aplica a la i3a1en
local 3a0& = 1raphic0$newMa0&( '1allina$Jp1' )
i3a1e"0etMa0&( 3a0& ) -- 3etoo
-- A.ento0 e to8ue 0ore la i3a1en 0e
en3a0caran a lo0 lV3ite0 e la 3W0cara
--(Cie3pre rectan1ular para una i3a1en
inepeniente3ente el contenio e la i3a1en)
i3a1e$i0QitDe0tMa0&e = true
-- ca3iano e ta3aXoi3a1e$3a0&CcaleE i3a1e$3a0&CcaleR =
Poniendo mas!a"a a 'a ima)e
-- Areate and position ima!e to be masDed
local ima!e = displa#ne3.ma!eect(
ima!epn!4 TR4 ;>? )
ima!e&translate( displa#contentAenter24
displa#contentAenterS )
-- Areate masD and appl# to ima!e
local masD = !raphicsne38asD( circlemasDpn!
)
ima!e&set8asD( masD )
-- 0rans"orm masD
ima!emasD'cale24 ima!emasD'caleS = >4>
8/18/2019 Manual Corona SDK v1
15/18
p"opiedad pa"et (#
local !roup = displa#ne3Jroup() X crea !rupo
local rect = displa#ne3ect( ;4 ;4 G4
G )
rect&setBillAolor( T )!roup&insert( rect ) X instera (evitar)
rectparent&remove( rect ) --removes rect "rom
!roup
Poiedo mas!a"a a ' )"'po
local ! = displa#ne3Jroup()
-- Areate and position ima!e to be masDed4 and
insert into !roup
local ima!e = displa#ne3.ma!eect( !4
ima!epn!4 TR4 ;>? )
-- Aenter the @ispla# Jroup
!&translate( displa#contentAenter24
displa#contentAenterS )
local masD = !raphicsne38asD(circlemasDpn!)
!&set8asD(masD)
"ota!i se!illa
local rect = displa#ne3ect( ;4 ;4 G4
G )
rectrotation = ?G
t"asi!i
local rect = displa#ne3ect( T4 ;G4 ;4 ;G
)
rect&setBillAolor( ;4 4 )
--rectrotation = -?G
local reverse = -- bit
-- "uncion
local "unction rocDect()
i" ( reverse == ) then reverse = ;
-- tiempo para la transicion
transitionto(rect4 Etime = ;4
x=>H)
else
reverse =
transitionto(rect4 Etime = ;4
x=TH)
end
end
--tiempo de inicio # duracion de cada ciclo dela "uncin
timerper"orm,ith@ela#( >4 rocDect4 ) --
epite siempre
"ota!io !o t"asi!i
local rect = displa#ne3ect( G4 G4 ;4
;G )
rect&setBillAolor( ;4 4 )
rectrotation = -?G
local reverse = ;
local "unction rocDect()
!"ea" !a"tas
local car0 = i0pla,$newLroup() -- 1rupo
e carta0
-- crear e.ento (toSac& o toront)function 0enDoSac&( e.ent )
if ( e.ent$pha0e == 'e1an' ) then
e.ent$tar1et"toront()
en
return true
en
for i=I o
--1rupo e ele3ento0 e uan carta
local carLroup = i0pla,$newLroup()
-- ;ar outline
local carKect =
i0pla,$newKouneKect(carLroup 22 22
I UI )
carKect$0tro&ePith =
carKect"0etill;olor( )
carKect"0etCtro&e;olor( 2 2 2 2$ )
carLroup"in0ert(carKect)
-- ;ar .alue0
local carOalue =i0pla,$newDet( carLroup i
carKect$contentPith - U
nati.e$0,0te3ontSol )
carOalue"0etill;olor( 2 2 )
local carOalue =
i0pla,$newDet( carLroup i Y
carKect$contentQei1ht - Y
nati.e$0,0te3ontSol )
carOalue"0etill;olor( 2 2 )
carLroup$ = (i * I) carLroup$, = (i * I)
8/18/2019 Manual Corona SDK v1
16/18
i" ( reverse == ) then
reverse = ;
transitionto( rect4 E rotation=-?G4
time=G4 transition=easin!in$utAubic H )
else
reverse = transitionto( rect4 E rotation=?G4
time=G4 transition=easin!in$utAubic H )
end
end
timerper"orm,ith@ela#( 4 rocDect4 ) --
epeat "orever
car0"in0ert( carLroup )
-- a1re1ano e.ento a un 1rupo
carLroup"aA.ent:i0tener( 'touch'
0enDoSac& )
en
p"opiedad %8= (e0to uica en el puntoone le inica0#
--
local rect = displa#ne3ect( 4 4 G4 G )
rectx = ;
rect# = ;
Esto a'meta e % o =
local cuarao = i0pla,$newKect( 22 22
I2 I2 )
cuarao"0etill;olor( 2 2 )cuarao"tran0late(22 22)
p"opiedad %S!ale (!ambia tamao delob6eto#
local rect; = displa#ne3ect( ;4 TG4 ;G4 G
)
rect;&setBillAolor( ;4 ;4 ; )
rect;rotation=F
-- !ira el rectan!ulo hori5ontalmente
rect;x'cale = -;
local rect> = displa#ne3ect( ;>G4 ;TG4 G4 G
)
rect>&setBillAolor( ;4 4 )
rect>x'cale = > -- cambia la escala en x a
>%rect$,Ccale = $I -- ca3ia la e0cala en , aI2%
lee la "'ta dode alma!eas el @mai
local line = i0pla,$new:ine( 22 H2 U GI
)
print('line$Fefine" ' $$ line$Fefine )
lee la "'ta del mai@l'a = la lieadode &'e e!o el 'ltimo !ambio
local line = i0pla,$new:ine( 22 H2 U GI
)
line$rotation = I
print('line$Fla0t;han1e" ' $$line$Fla0t;han1e )
8/18/2019 Manual Corona SDK v1
17/18
da las p"opiedades del ob6eto
local J0on = re8uire( 'J0on' )
local line = i0pla,$new:ine( 22 H2 U GI
)
line$rotation = I
print('line$Fpropertie0" ' $$
J0on$prettif,( line$Fpropertie0 ) )
M?todo de ise"!i di"e!ta
local 3,Lroup = i0pla,$newLroup()
local 3,63a1e = i0pla,$new63a1e( 3,Lroup
'i3a1e$pn1' )
M?todo di"e!to
local m#Jroup = displa#ne3Jroup()
local m#.ma!e = displa#ne3.ma!e( ima!epn! )
m#Jroup&insert( m#.ma!e )
O"de de los ob6etos
--creamos el !rupo
local m#Jroup = displa#ne3Jroup()
--creamos los obetos
local square = displa#ne3ect( m#Jroup4 4 4 ;4 ; ) --red square is at the bottom
square&setBillAolor( ;4 4 )
local circle = displa#ne3Aircle( m#Jroup4 F4 G4 G ) --!reen circle is in the middle
circle&setBillAolor( 4 ;4 )local rect = displa#ne3ect( m#Jroup4 4 G4 ;>4 R ) --blue rectan!le is at the top
rect&setBillAolor( 4 4 ; )
m#Jroup&translate(;4;)
-- creamos el parend de square
local parent = squareparent
-- lo ponemos en su parent
parent&insert( square )
-- # #a podemos moverlo a la capa que queramos
parent&insert(;4 circle )
Re&e"e!ia a ob6etos ('sado 'a tabla#
-- crea3o0 un 1rupo
local 08uare0 = i0pla,$newLroup()
--crea3o0 lo0 cuarao0
local reC8uare = i0pla,$newKect( 08uare0 2 2 2 2 )
local reC8uare = i0pla,$newKect( 08uare0 2 I2 2 2 )
local reC8uare = i0pla,$newKect( 08uare0 2 22 2 2 )
--lo0 pinat3o0 e color roJoreC8uare"0etill;olor( 2 2 )
8/18/2019 Manual Corona SDK v1
18/18
reC8uare"0etill;olor( 2 2 )
reC8uare"0etill;olor( 2 2 )
--crea3o0 lo0 cuarao0
local whiteC8uare = i0pla,$newKect( 08uare0 2 2 2 2 )
local whiteC8uare = i0pla,$newKect( 08uare0 2 U2 2 2 )
--o0 pinat3o0 e color alnco whiteC8uare"0etill;olor( )
whiteC8uare"0etill;olor( )
08uare0"tran0late(22I2)
--pone3o0 0olo lo0 cuarao0 roJo0 en la tala
local reC8uare0 = { reC8uare reC8uare reC8uare }
--3anipula3o0 la tala u0ano un for
for i = #reC8uare0 o
--3anipulate the 08uare at the current ine (i) reC8uare0[i$ = reC8uare0[i$ + 22 -- lo0 3o.e3o0 22 a la erecha
reC8uare0[i"0cale( 2$I 2$I ) -- lo0 e0calo0 a I2 %
en
Bo""ado di"e!to
displa#remove ( m#$bect )
m#$bect = nil --set re"erence to nil
--$
m#$bect&remove'el"()
m#$bect = nil --set re"erence to nil
--$
m#Jroup&remove( m#$bect )
m#$bect = nil --set re"erence to nil
Bo""ado ' )"'po
displa#remove( m#Jroup )
m#Jroup = nil
--$
m#Jroup&remove'el"()
m#Jroup = nil