Variable      j = 10      -- global variable      local i = 1 -- local variable      if i > 20 then        local x      --...
display.newText()Creates a text object with its top-left corner at (left, top). The local origin is at thecenter of the te...
display.newImage( )Syntax:    object = display.newImage(filename [,baseDirectory] [,left,top])Example:    local myImage = ...
display.newRect()Syntax:    display.newRect( left, top, width, height )Example:   local myRectangle = display.newRect(0, 0...
display.newCircle()Syntax:    display.newCircle( xCenter, yCenter, radius )Example:   local myCircle = display.newCircle( ...
display.newGroup()Description:Creates a group in which you can add and remove child display objects. Initially,there are n...
display.newGroup()
Basic Touch Handlingobject:addEventListenerSyntax:!         object:addEventListener( eventName, listener )Example:        ...
timer.performWithDelay()timer.performWithDelay()timer.pausetimer.cancelDescription:    Call a specified function after a de...
timer.pause()Description:     Pauses a timer started with timer.performWithDelay.Syntax:!     result = timer.pause( timerI...
timer.resume()Description:         Resumes a timer that was paused with timer.pause.Syntax:!         result = timer.resume...
audioDescription:     Plays audio.Plays the audio specified by the audio handle on a channel. If a channel isnot explicitly...
-- play soundlocal function playSound(event)"    laserChanel = audio.play(laserSound,{ channel=1, loops=0,fadein=5000}) --...
PhysicsOverviewCorona makes it very easy to add physics to your games, even if youve neverworked with a physics engine bef...
physics.start()Description:    This function start the physics simulation and should be called beforeany other physics fun...
local foot = display.newRect(0,0,display.contentWidth, 4)foot:setFillColor(167,96,20)foot.y = display.contentHeight--foot....
StoryboardScene TemplateDescription:This scene template can be used as a bare-bones scene to be used with theStoryboard AP...
Build and deploy to device
Corona sdk
Upcoming SlideShare
Loading in …5
×

Corona sdk

732 views

Published on

พื่นฐานภาษา Lua และ Corona SDK

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
732
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Corona sdk

  1. 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))) --> stringControl Structures - if then else! - while Loop - for Loop
  2. 2. display.newText()Creates a text object with its top-left corner at (left, top). The local origin is at thecenter 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 = 32myText.text.x = display.contentCenterXmyText.text.y = display.contentCenterY
  3. 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. 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. 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. 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; thereference 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 = 10group1.y = 20--print(group1.width)local imgGroup2 = display.newImage("images/group2.png")group2:insert(imgGroup2)group2.x = 160group2.y = 20local rect = display.newRect(0,0, 120, 50)rect.x = group1.width/2rect.y = group1.height/2group1:insert(rect)local circle = display.newCircle(0,0, 25)circle.x = group2.width/2circle.y = group2.height/2group2:insert(circle)
  7. 7. display.newGroup()
  8. 8. Basic Touch Handlingobject:addEventListenerSyntax:! 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. 9. timer.performWithDelay()timer.performWithDelay()timer.pausetimer.cancelDescription: 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. 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.contentCenterXtime_txt.y = display.contentCenterYlocal time1local 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. 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. 12. audioDescription: Plays audio.Plays the audio specified by the audio handle on a channel. If a channel isnot explicitly specified, an available channel will be automatically chosenfor you if available.Syntax:! audio.play( audioHandle [, { [channel=c] [, loops=l] [,! ! ! duration=d] [, fadein=f] [, onComplete=o]  } ])Example:-- audiolocal buttonGroup = display.newGroup()local play = display.newImage("images/play.png")play.x = buttonGroup.widthlocal pause = display.newImage("images/pause.png")pause.x = play.width + 10local resume = display.newImage("images/resume.png")resume.x = (pause.x + resume.width) + 10buttonGroup:insert(play)buttonGroup:insert(pause)buttonGroup:insert(resume)buttonGroup.x = display.contentCenterX - 60buttonGroup.y = 400-- load soundlocal laserSound = audio.loadSound("sounds/MLJ.mp3")local laserChanel
  13. 13. -- play soundlocal function playSound(event)" laserChanel = audio.play(laserSound,{ channel=1, loops=0,fadein=5000}) -- play the laser on any available channelendplay:addEventListener("tap", playSound)-- pause soundlocal function pauseSound(event)" audio.pause(laserChanel)"endpause:addEventListener("tap", pauseSound)--resume soundlocal function resumeSound(event)" audio.resume(laserChanel)endresume:addEventListener("tap", resumeSound)
  14. 14. PhysicsOverviewCorona makes it very easy to add physics to your games, even if youve neverworked with a physics engine before. While the underlying engine is built aroundthe well-known Box2D, weve taken a radically different design approach thateliminates most of the coding that is traditionally required.Why use Physics?Say you want your game to have a bouncing ball, Coronas Physics engine makesthis easy. In just a few lines of code you can have a ball bouncing around thescreen!You can also use Physics for action collisions. Say you want to have your playerwalk into a certain area on the screen and have an action take place, you caneasily do this by using Coronas 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" sampleproject for an example of how to toggle it on the fly.Syntax:physics.setDrawMode( mode )Example:physics.setDrawMode( "debug" ) -- shows collision engine outlinesonlyphysics.setDrawMode( "hybrid" ) -- overlays collision outlines onnormal Corona objectsphysics.setDrawMode( "normal" ) -- the default Corona renderer,with no collision outlines
  15. 15. physics.start()Description: This function start the physics simulation and should be called beforeany other physics functions.Syntax:! physics.start( noSleep )Example:local physics = require "physics"physics.start()-- step 1 setDrawMode--physics.setDrawMode( "debug" ) -- shows collision engineoutlines only--physics.setDrawMode( "hybrid" ) -- overlays collision outlineson normal Corona objects--physics.setDrawMode( "normal" ) -- the default Corona renderer,with no collision outlines-- step 2 physics.addBodylocal ball = display.newCircle(0,0, 25)ball:setFillColor(252,151,241)ball.x = display.contentCenterXball.y = display.contentCenterY/4physics.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.contentWidthphysics.addBody( right_wall, "static", { density = 1.0, friction =0.3, bounce = 0.5} )
  16. 16. local foot = display.newRect(0,0,display.contentWidth, 4)foot:setFillColor(167,96,20)foot.y = display.contentHeight--foot.rotation = -2physics.addBody( foot, "static", { density = 1.0, friction = 0.3,bounce = 0.5} )
  17. 17. StoryboardScene TemplateDescription:This scene template can be used as a bare-bones scene to be used with theStoryboard API.Syntax:Example: SceneTemplate.luastoryboard.gotoScene()Description: Used to transition to a specific scene (determined by scenes modulename). 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. 18. Build and deploy to device

×