0

Corona SDK Mobile App Development Tutorial – Part 2

Corona SDK Mobile App Development Tutorial – Part 2

Read Corona SDK Mobile App Development Tutorial – Part 1 here

In Corona SDK Mobile App Development Tutorial – Part 2 , we will talk about below items.

1) How to display an object in the app?

2) How to move the object from one position to another?

3) Playing Audio Files

4) Running the App in simulator

Lets move on to details.

1) How to display an object in the app?

Displaying an object on screen is simple and easy.

local object1 = display.newImage("vehicle.png",120,120)

That’s it. This single statement displays your object “vehicle.png” on screen at thecoordinates 120,120 on screen as below. Just make sure you keep the vehicle.png image at the base location where your main.lua resides.

More info on display.newImage at http://docs.coronalabs.com/api/library/display/newImage.html

Now go to simulator and relaunch your project ( shortcut Ctrl+R). You should see your screen as below.

Below is my vehicle.png

Corona SDK Sample Image

Corona SDK Sample Image

 

Below is the simulator screen

Corona Simulator Image 1

Corona Simulator Image 1

 

2) How to move the object from one position to another?

local object1 = display.newImage("vehicle.png",120,120)
object1.x = 200
object1.y = 300

object1.x -> Sets the x position of the Object1
object1.y -> Sets the y position of the Object1

Corona Simulator Image 2

Corona Simulator Image 2

 

3) Playing Audio Files In The App

local sampleSound = audio.loadSound("sampleSound.wav")
local sampleChannel = audio.play( sampleSound )

More on audio playing at http://docs.coronalabs.com/legacy/api/library/audio/play.html

audio.pause() and audio.stop() functions can be called to pause the audio and stop the audio respectively.

4) Running the App in simulator

Once your have are ready with your code, you can run the code by pressing Ctrl+R

Corona Code Sample 1

Corona Code Sample 1

 

Corona Simulator Image 3

Corona Simulator Image 3

 

Corona SDK Mobile App Development Tutorial – Part 3