SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Variable

      j = 10      -- global variable
      local i = 1 -- local variable

      if i > 20 then
        local x      -- local to the "then" body
        x = 20
        print(x + 2)
      else
        print(x)     --> 10 (the global one)
      end

      print(x)           --> 10 (the global one)

Types and Values
	

     print(type("Hello world")) --> string

       print(type(10))
     
  --> number

       print(type(print))
 
   --> function

       print(type(type))
 
    --> function

       print(type(true))
 
    --> boolean

       print(type(nil))
   
   --> nil

       print(type(type(X)))
   --> string

Control Structures
        - if then else
!       - while Loop
        - for Loop
display.newText()
Creates a text object with its top-left corner at (left, top). The local origin is at the
center of the text; the reference point is initialized to this local origin. By default,
the text color is white (255, 255, 255).


Syntax:


           display.newText(string, left, top,
                                          [width, height,] font, size )



local myText = display.newText("Hello World!", 0, 0, native.systemFont, 16)
myText:setTextColor(255, 255, 255)
 
myText.text = "Hello!"
myText.size = 32


myText.text.x = display.contentCenterX
myText.text.y = display.contentCenterY
display.newImage( )
Syntax:

    object = display.newImage(filename [,baseDirectory] [,left,top])


Example:



    local myImage = display.newImage( "images/rocket2.png")

    myImage.x = 150

    myImage.y = 250
display.newRect()
Syntax:

    display.newRect( left, top, width, height )


Example:

   local myRectangle = display.newRect(0, 0, 150, 50)

   myRectangle.strokeWidth = 3

   myRectangle:setFillColor(140, 140, 140)

   myRectangle:setStrokeColor(180, 180, 180)
display.newCircle()
Syntax:


    display.newCircle( xCenter, yCenter, radius )




Example:

   local myCircle = display.newCircle( 100, 100, 30 )

   myCircle:setFillColor(128,128,128)


   myCircle.strokeWidth = 5

   myCircle:setStrokeColor(128,0,0)  -- red
display.newGroup()
Description:
Creates a group in which you can add and remove child display objects. Initially,
there are no children in a group. The local origin is at the parent’s origin; the
reference point is initialized to this local origin.


Syntax:

    display.newGroup()


Example:
local group1 = display.newGroup()
local group2 = display.newGroup()

local imgGroup1 = display.newImage("images/group1.png")
group1:insert(imgGroup1);
group1.x = 10
group1.y = 20
--print(group1.width)

local imgGroup2 = display.newImage("images/group2.png")

group2:insert(imgGroup2)
group2.x = 160
group2.y = 20

local rect = display.newRect(0,0, 120, 50)
rect.x = group1.width/2
rect.y = group1.height/2
group1:insert(rect)

local circle = display.newCircle(0,0, 25)
circle.x = group2.width/2
circle.y = group2.height/2
group2:insert(circle)
display.newGroup()
Basic Touch Handling
object:addEventListener

Syntax:
!         object:addEventListener( eventName, listener )

Example:


          local circle = display.newCircle(0,0, 25)
          circle.x = display.contentCenterX
          circle.y = display.contentCenterY


          local function myListener( self, event )
    
     
      if event.phase == "began" then

        
 
      
       print( "Listener called with event of type " .. event.name )

    
     
      elseif event.phase == "moved" then

        
 
      
       -- User has moved their finger, while touching

    
     
      elseif event.phase == "ended" or event.phase == "cancelled" then

        

       
      -- Touch has ended; user has lifted their finger
    
    
       end

    
     
      return true    -- IMPORTANT

         
      end


         circle:addEventListener( "touch", myListener )
timer.performWithDelay()
timer.performWithDelay()
timer.pause
timer.cancel

Description:

    Call a specified function after a delay.


Syntax:

    timer.performWithDelay( delay, listener [, iterations] )


Example:

     local time_txt = display.newText("Time", 0,0,
native.systemFont, 25)

     time_txt.x = display.contentCenterX

     time_txt.y = display.contentCenterY



           local   sec = 0
    
       local   function listener( event )
    
       
        sec = sec + 1;
        
   
        time_txt.text = sec
    
       end



           timer.performWithDelay(1000, listener,0 )
timer.pause()
Description:

     Pauses a timer started with timer.performWithDelay.

Syntax:
!     result = timer.pause( timerId )

Example:
local time_txt = display.newText("Time",
0,0,native.systemFont,25)
time_txt.x = display.contentCenterX
time_txt.y = display.contentCenterY

local time1
local sec = 0
 local function listener( event )
 "   sec = sec + 1;
    time_txt.text = sec

     if sec >= 10 then
     "time_txt.text = "pause"
     "result = timer.pause( time1 )
     "
     end
 end
 time1 = timer.performWithDelay(1000,
listener, 0 )
timer.resume()
Description:

         Resumes a timer that was paused with timer.pause.

Syntax:
!         result = timer.resume( timerId )

Example:
    local function listener( event )
    "   sec = sec + 1;
       time_txt.text = sec

          if sec > 10 then
          "time_txt.text = "pause"
          "result = timer.pause(time1) -- Pause
          "sec = 0
"          time_txt.text = “resume”
          "result = timer.resume(time1)
          end
    end

    time1 = timer.performWithDelay(1000, listener, 0 )
audio
Description:

     Plays audio.

Plays the audio specified by the audio handle on a channel. If a channel is
not explicitly specified, an available channel will be automatically chosen
for you if available.

Syntax:
!     audio.play( audioHandle [, { [channel=c] [, loops=l] [,
!     !    !    duration=d] [, fadein=f] [, onComplete=o]  } ])

Example:
-- audio

local buttonGroup = display.newGroup()

local play = display.newImage("images/play.png")
play.x = buttonGroup.width
local pause = display.newImage("images/pause.png")
pause.x = play.width + 10
local resume = display.newImage("images/resume.png")
resume.x = (pause.x + resume.width) + 10

buttonGroup:insert(play)
buttonGroup:insert(pause)
buttonGroup:insert(resume)

buttonGroup.x = display.contentCenterX - 60
buttonGroup.y = 400

-- load sound
local laserSound = audio.loadSound("sounds/MLJ.mp3")
local laserChanel
-- play sound
local function playSound(event)
"    laserChanel = audio.play(laserSound,{ channel=1, loops=0,
fadein=5000}) -- play the laser on any available channel
end
play:addEventListener("tap", playSound)

-- pause sound
local function pauseSound(event)
"    audio.pause(laserChanel)"
end
pause:addEventListener("tap", pauseSound)

--resume sound
local function resumeSound(event)
"    audio.resume(laserChanel)
end
resume:addEventListener("tap", resumeSound)
Physics
Overview
Corona makes it very easy to add physics to your games, even if you've never
worked with a physics engine before. While the underlying engine is built around
the well-known Box2D, we've taken a radically different design approach that
eliminates most of the coding that is traditionally required.


Why use Physics?
Say you want your game to have a bouncing ball, Corona's Physics engine makes
this easy. In just a few lines of code you can have a ball bouncing around the
screen!


You can also use Physics for action collisions. Say you want to have your player
walk into a certain area on the screen and have an action take place, you can
easily do this by using Corona's Physics engine and using a sensor Physics body.



local physics = require "physics"



physics.setDrawMode()
Description:

    Selects one of three possible rendering modes for the physics engine.
This mode may be changed at any time -- see the "DebugDraw" sample
project for an example of how to toggle it on the fly.

Syntax:
physics.setDrawMode( mode )

Example:
physics.setDrawMode( "debug" ) -- shows collision engine outlines
only
physics.setDrawMode( "hybrid" ) -- overlays collision outlines on
normal Corona objects
physics.setDrawMode( "normal" ) -- the default Corona renderer,
with no collision outlines
physics.start()
Description:

    This function start the physics simulation and should be called before
any other physics functions.

Syntax:
!     physics.start( noSleep )

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

-- step 1 setDrawMode

--physics.setDrawMode( "debug" ) -- shows collision engine
outlines only
--physics.setDrawMode( "hybrid" ) -- overlays collision outlines
on normal Corona objects
--physics.setDrawMode( "normal" ) -- the default Corona renderer,
with no collision outlines

-- step 2 physics.addBody

local ball = display.newCircle(0,0, 25)
ball:setFillColor(252,151,241)
ball.x = display.contentCenterX
ball.y = display.contentCenterY/4
physics.addBody( ball, { density = 1.0, friction = 0.3, bounce =
0.2, radius = 25 } )

local left_wall = display.newRect(0,0,4,display.contentHeight)
left_wall:setFillColor(167,96,20)
physics.addBody( left_wall, "static", { density = 1.0, friction =
0.3, bounce = 0.5} )

local right_wall = display.newRect(0,0,4,display.contentHeight)
right_wall:setFillColor(167,96,20)
right_wall.x = display.contentWidth
physics.addBody( right_wall, "static", { density = 1.0, friction =
0.3, bounce = 0.5} )
local foot = display.newRect(0,0,display.contentWidth, 4)
foot:setFillColor(167,96,20)
foot.y = display.contentHeight
--foot.rotation = -2
physics.addBody( foot, "static", { density = 1.0, friction = 0.3,
bounce = 0.5} )
Storyboard
Scene Template
Description:
This scene template can be used as a bare-bones scene to be used with the
Storyboard API.

Syntax:
Example: SceneTemplate.lua


storyboard.gotoScene()
Description:

    Used to transition to a specific scene (determined by scene's module
name). Internally, this will handle all loading/unloading of the scenes.
Scenes may also be explicitly unloaded/removed by the user.

Syntax:
Format 1:

"     storyboard.gotoScene( sceneName [, effect, effectTime] )


Example:
Format 1:

local storyboard = require "storyboard"
storyboard.gotoScene( "scene1", "fade", 500 )
Build and deploy to device
Corona sdk

Contenu connexe

Tendances

Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212Mahmoud Samir Fayed
 
Intro to OTP in Elixir
Intro to OTP in ElixirIntro to OTP in Elixir
Intro to OTP in ElixirJesse Anderson
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31Mahmoud Samir Fayed
 
Kotlin - Coroutine
Kotlin - CoroutineKotlin - Coroutine
Kotlin - CoroutineSean Tsai
 
The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180Mahmoud Samir Fayed
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185Mahmoud Samir Fayed
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceTobias Pfeiffer
 
The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212Mahmoud Samir Fayed
 
밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AINAVER Engineering
 
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210Mahmoud Samir Fayed
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수용 최
 

Tendances (20)

Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.9 book - Part 62 of 210
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
Intro to OTP in Elixir
Intro to OTP in ElixirIntro to OTP in Elixir
Intro to OTP in Elixir
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212The Ring programming language version 1.10 book - Part 81 of 212
The Ring programming language version 1.10 book - Part 81 of 212
 
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.4.1 book - Part 15 of 31
 
Kotlin - Coroutine
Kotlin - CoroutineKotlin - Coroutine
Kotlin - Coroutine
 
The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.2 book - Part 38 of 84
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185The Ring programming language version 1.5.4 book - Part 51 of 185
The Ring programming language version 1.5.4 book - Part 51 of 185
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
 
The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88The Ring programming language version 1.3 book - Part 41 of 88
The Ring programming language version 1.3 book - Part 41 of 88
 
The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212The Ring programming language version 1.10 book - Part 92 of 212
The Ring programming language version 1.10 book - Part 92 of 212
 
밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI밑바닥부터 시작하는 의료 AI
밑바닥부터 시작하는 의료 AI
 
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
 

Similaire à Corona sdk

The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212Mahmoud Samir Fayed
 
Visual Basic(Vb) practical
Visual Basic(Vb) practicalVisual Basic(Vb) practical
Visual Basic(Vb) practicalRahul juneja
 
The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202Mahmoud Samir Fayed
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181Mahmoud Samir Fayed
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and ProfitAdil Akhter
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31Mahmoud Samir Fayed
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOWMark Chang
 
The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185Mahmoud Samir Fayed
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정SeungChul Kang
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88Mahmoud Samir Fayed
 

Similaire à Corona sdk (20)

The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212
 
Visual Basic(Vb) practical
Visual Basic(Vb) practicalVisual Basic(Vb) practical
Visual Basic(Vb) practical
 
The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189
 
The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196
 
The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202
 
Monadologie
MonadologieMonadologie
Monadologie
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210
 
The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180The Ring programming language version 1.5.1 book - Part 65 of 180
The Ring programming language version 1.5.1 book - Part 65 of 180
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
 
FS2 for Fun and Profit
FS2 for Fun and ProfitFS2 for Fun and Profit
FS2 for Fun and Profit
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31
 
NTU ML TENSORFLOW
NTU ML TENSORFLOWNTU ML TENSORFLOW
NTU ML TENSORFLOW
 
The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
 

Corona sdk

  • 1. Variable j = 10 -- global variable local i = 1 -- local variable if i > 20 then local x -- local to the "then" body x = 20 print(x + 2) else print(x) --> 10 (the global one) end print(x) --> 10 (the global one) Types and Values print(type("Hello world")) --> string print(type(10)) --> number print(type(print)) --> function print(type(type)) --> function print(type(true)) --> boolean print(type(nil)) --> nil print(type(type(X))) --> string Control Structures - if then else ! - while Loop - for Loop
  • 2. display.newText() Creates a text object with its top-left corner at (left, top). The local origin is at the center of the text; the reference point is initialized to this local origin. By default, the text color is white (255, 255, 255). Syntax: display.newText(string, left, top,                                 [width, height,] font, size ) local myText = display.newText("Hello World!", 0, 0, native.systemFont, 16) myText:setTextColor(255, 255, 255)   myText.text = "Hello!" myText.size = 32 myText.text.x = display.contentCenterX myText.text.y = display.contentCenterY
  • 3. display.newImage( ) Syntax: object = display.newImage(filename [,baseDirectory] [,left,top]) Example: local myImage = display.newImage( "images/rocket2.png") myImage.x = 150 myImage.y = 250
  • 4. display.newRect() Syntax: display.newRect( left, top, width, height ) Example: local myRectangle = display.newRect(0, 0, 150, 50) myRectangle.strokeWidth = 3 myRectangle:setFillColor(140, 140, 140) myRectangle:setStrokeColor(180, 180, 180)
  • 5. display.newCircle() Syntax: display.newCircle( xCenter, yCenter, radius ) Example: local myCircle = display.newCircle( 100, 100, 30 ) myCircle:setFillColor(128,128,128) myCircle.strokeWidth = 5 myCircle:setStrokeColor(128,0,0)  -- red
  • 6. display.newGroup() Description: Creates a group in which you can add and remove child display objects. Initially, there are no children in a group. The local origin is at the parent’s origin; the reference point is initialized to this local origin. Syntax: display.newGroup() Example: local group1 = display.newGroup() local group2 = display.newGroup() local imgGroup1 = display.newImage("images/group1.png") group1:insert(imgGroup1); group1.x = 10 group1.y = 20 --print(group1.width) local imgGroup2 = display.newImage("images/group2.png") group2:insert(imgGroup2) group2.x = 160 group2.y = 20 local rect = display.newRect(0,0, 120, 50) rect.x = group1.width/2 rect.y = group1.height/2 group1:insert(rect) local circle = display.newCircle(0,0, 25) circle.x = group2.width/2 circle.y = group2.height/2 group2:insert(circle)
  • 8. Basic Touch Handling object:addEventListener Syntax: ! object:addEventListener( eventName, listener ) Example: local circle = display.newCircle(0,0, 25) circle.x = display.contentCenterX circle.y = display.contentCenterY local function myListener( self, event ) if event.phase == "began" then print( "Listener called with event of type " .. event.name ) elseif event.phase == "moved" then -- User has moved their finger, while touching elseif event.phase == "ended" or event.phase == "cancelled" then -- Touch has ended; user has lifted their finger end return true -- IMPORTANT end circle:addEventListener( "touch", myListener )
  • 9. timer.performWithDelay() timer.performWithDelay() timer.pause timer.cancel Description: Call a specified function after a delay. Syntax: timer.performWithDelay( delay, listener [, iterations] ) Example: local time_txt = display.newText("Time", 0,0, native.systemFont, 25) time_txt.x = display.contentCenterX time_txt.y = display.contentCenterY local sec = 0 local function listener( event ) sec = sec + 1; time_txt.text = sec end timer.performWithDelay(1000, listener,0 )
  • 10. timer.pause() Description: Pauses a timer started with timer.performWithDelay. Syntax: ! result = timer.pause( timerId ) Example: local time_txt = display.newText("Time", 0,0,native.systemFont,25) time_txt.x = display.contentCenterX time_txt.y = display.contentCenterY local time1 local sec = 0 local function listener( event ) " sec = sec + 1; time_txt.text = sec if sec >= 10 then "time_txt.text = "pause" "result = timer.pause( time1 ) " end end time1 = timer.performWithDelay(1000, listener, 0 )
  • 11. timer.resume() Description: Resumes a timer that was paused with timer.pause. Syntax: ! result = timer.resume( timerId ) Example: local function listener( event ) " sec = sec + 1; time_txt.text = sec if sec > 10 then "time_txt.text = "pause" "result = timer.pause(time1) -- Pause "sec = 0 " time_txt.text = “resume” "result = timer.resume(time1) end end time1 = timer.performWithDelay(1000, listener, 0 )
  • 12. audio Description: Plays audio. Plays the audio specified by the audio handle on a channel. If a channel is not explicitly specified, an available channel will be automatically chosen for you if available. Syntax: ! audio.play( audioHandle [, { [channel=c] [, loops=l] [, ! ! ! duration=d] [, fadein=f] [, onComplete=o]  } ]) Example: -- audio local buttonGroup = display.newGroup() local play = display.newImage("images/play.png") play.x = buttonGroup.width local pause = display.newImage("images/pause.png") pause.x = play.width + 10 local resume = display.newImage("images/resume.png") resume.x = (pause.x + resume.width) + 10 buttonGroup:insert(play) buttonGroup:insert(pause) buttonGroup:insert(resume) buttonGroup.x = display.contentCenterX - 60 buttonGroup.y = 400 -- load sound local laserSound = audio.loadSound("sounds/MLJ.mp3") local laserChanel
  • 13. -- play sound local function playSound(event) " laserChanel = audio.play(laserSound,{ channel=1, loops=0, fadein=5000}) -- play the laser on any available channel end play:addEventListener("tap", playSound) -- pause sound local function pauseSound(event) " audio.pause(laserChanel)" end pause:addEventListener("tap", pauseSound) --resume sound local function resumeSound(event) " audio.resume(laserChanel) end resume:addEventListener("tap", resumeSound)
  • 14. Physics Overview Corona makes it very easy to add physics to your games, even if you've never worked with a physics engine before. While the underlying engine is built around the well-known Box2D, we've taken a radically different design approach that eliminates most of the coding that is traditionally required. Why use Physics? Say you want your game to have a bouncing ball, Corona's Physics engine makes this easy. In just a few lines of code you can have a ball bouncing around the screen! You can also use Physics for action collisions. Say you want to have your player walk into a certain area on the screen and have an action take place, you can easily do this by using Corona's Physics engine and using a sensor Physics body. local physics = require "physics" physics.setDrawMode() Description: Selects one of three possible rendering modes for the physics engine. This mode may be changed at any time -- see the "DebugDraw" sample project for an example of how to toggle it on the fly. Syntax: physics.setDrawMode( mode ) Example: physics.setDrawMode( "debug" ) -- shows collision engine outlines only physics.setDrawMode( "hybrid" ) -- overlays collision outlines on normal Corona objects physics.setDrawMode( "normal" ) -- the default Corona renderer, with no collision outlines
  • 15. physics.start() Description: This function start the physics simulation and should be called before any other physics functions. Syntax: ! physics.start( noSleep ) Example: local physics = require "physics" physics.start() -- step 1 setDrawMode --physics.setDrawMode( "debug" ) -- shows collision engine outlines only --physics.setDrawMode( "hybrid" ) -- overlays collision outlines on normal Corona objects --physics.setDrawMode( "normal" ) -- the default Corona renderer, with no collision outlines -- step 2 physics.addBody local ball = display.newCircle(0,0, 25) ball:setFillColor(252,151,241) ball.x = display.contentCenterX ball.y = display.contentCenterY/4 physics.addBody( ball, { density = 1.0, friction = 0.3, bounce = 0.2, radius = 25 } ) local left_wall = display.newRect(0,0,4,display.contentHeight) left_wall:setFillColor(167,96,20) physics.addBody( left_wall, "static", { density = 1.0, friction = 0.3, bounce = 0.5} ) local right_wall = display.newRect(0,0,4,display.contentHeight) right_wall:setFillColor(167,96,20) right_wall.x = display.contentWidth physics.addBody( right_wall, "static", { density = 1.0, friction = 0.3, bounce = 0.5} )
  • 16. local foot = display.newRect(0,0,display.contentWidth, 4) foot:setFillColor(167,96,20) foot.y = display.contentHeight --foot.rotation = -2 physics.addBody( foot, "static", { density = 1.0, friction = 0.3, bounce = 0.5} )
  • 17. Storyboard Scene Template Description: This scene template can be used as a bare-bones scene to be used with the Storyboard API. Syntax: Example: SceneTemplate.lua storyboard.gotoScene() Description: Used to transition to a specific scene (determined by scene's module name). Internally, this will handle all loading/unloading of the scenes. Scenes may also be explicitly unloaded/removed by the user. Syntax: Format 1: " storyboard.gotoScene( sceneName [, effect, effectTime] ) Example: Format 1: local storyboard = require "storyboard" storyboard.gotoScene( "scene1", "fade", 500 )
  • 18. Build and deploy to device