How Can I Add A Sound To A Button

I’m trying to make an app. I want people to touch the screen in a custom button, and then things happen:

touch and play a sound

produce an animation like shooting a laser beam

hit an object

and make that object dissapear.

Could you tell me if I can get help on this please.

Thank you

Hello,

Would you find a short video tutorial series useful? Not everybody likes the format of video tutorials, but some find it more “interactive” than a text tutorial. If so, this one comes to mind:

http://www.youtube.com/watch?v=Mw-TWx3CH84

Best regards,

Brent Sorrentino

I just watch the 4 videos, THEY ARE REALLY GOOD! I don’t know who made those but it;s very easy for beginners, and he explains thisngs really good, I got everything and everything worked really well, THANKS A LOT!

touch and play a sound – I Still did not get the sound part!

produce an animation like shooting a laser beam – The Angry moves ALL THE TIME, I just want the laser to shoot in response of an event (“Touch” a button) only then I will move the Angry or a Bullet or an image.

hit an object – This is collision, good, Now I need that instead of desapearing…


function onCollision (event)
        can:removeSelf()
end
Runtime:addEventListener (“collision”, onCollision)


Make an explosion sprite animation, something like this:


local sheet3 = graphics.newImageSheet( “explosion.png”, { width=512, height=256, numFrames=8 } )

– play 15 frames every 500 ms
local instance3 = display.newSprite( sheet3, { name=“explo”, start=1, count=8, time=5000 } )
instance3.x = 3 * display.contentWidth / 6 + 100
instance3.y = baseline - 20
instance3:play()


And how to put this two togheter, because I got a piece of code from one place and a pice from another.

And thank you for answering this e-mail, NOW I ACTUALLY FEEL THAT I’M NOT ALONE IN THIS NEW WORLD OF MAKING GAMES,

Thank you Brent.

Hi Victor,

Good to hear that the videos helped. I have another series by the same author which you might enjoy:

http://www.youtube.com/watch?v=0GtUxdSeWzk

And this page contains a huge list of useful links, including tutorials, templates, libraries, etc.

http://www.tandgapps.co.uk/resources/coronalabs-resources/

Have fun!

Brent

I already saw this video, I think is really nice and it will help me a lot.

I’m going to follow instructions and make it on my computer, it will take time because it’s long (14 videos)

but I will do that, thank you.

If I have questions on this I will let you know.

Just one question…

How can I do the same project on the iPad SIMULATOR?  I want to work for the iPad better. thanks

Hi Brent I watched 3 videos, so far so good.

First problem…

The two images are moving, scrolling fine. From right to left

but in the VIDEO the city2 is right after city1 so as soon as city1 movess -3 px then city2 enterFrame so it seems like a loop

– PROBLEM 1

mine I can see the city1 all the way moving, and is not only after city1 has left the screen or the view, then city2 enterFrame

so I have a lot of time with no image waht so ever.

– PROBLEM 2

City 3 starts to move fine, and after it leaves the screen, then I don’t see nothing

I star to see city 2 but no city3 and after a few seconds, city3 APPERAS all of a sudden in the middle of the screen!

------ THIS IS THE CODE I HAVE


display.setStatusBar (display.HiddenStatusBar)

local background = display.newImage (“bgIce.png”)

local nitas = display.newImage (“stalacnitasDown.png”)
nitas:setReferencePoint(display.BottomLeftReferencePoint)
nitas.x = 0
nitas.y = 320
nitas.speed = 1

local nitas2 = display.newImage (“stalacnitasDown.png”)
nitas2:setReferencePoint(display.BottomLeftReferencePoint)
nitas2.x = 0
nitas2.y = 320
nitas2.speed = 1

local titas = display.newImage (“stalactitasUp.png”)
titas:setReferencePoint(display.UpperLeftReferencePoint)
titas.x = 245
titas.y = 140
titas.speed = 1

local titas2 = display.newImage (“stalactitasUp.png”)
titas2:setReferencePoint(display.UpperLeftReferencePoint)
titas2.x = 245
titas2.y = 140
titas2.speed = 1

function scrollNitas(self,event)
    if self.x < -477 then
        self.x = 480
    else
        self.x = self.x - self.speed
    end
end

nitas.enterFrame = scrollNitas
Runtime:addEventListener (“enterFrame”, nitas)

nitas2.enterFrame = scrollNitas
Runtime:addEventListener (“enterFrame”, nitas2)

titas.enterFrame = scrollNitas
Runtime:addEventListener (“enterFrame”, titas)

titas2.enterFrame = scrollNitas
Runtime:addEventListener (“enterFrame”, titas2)

Please help me out, THANK YOU VERY MUCH!

PS. I have a video if I didnot explain myself good. Tell me if you need to see the video

How do I open the “consol window” to see the

print (“touch”)

If you are on a Mac, you launch /Applications/CoronaSDK/Corona Terminal

This will start up a terminal session which launches Corona SDK for you.  You can then see the messages in the terminal window.  There are several 3rd Party IDE’s like Glider, ZeroBraneStudio, Corona Complete, and what used to be Corona Project Manager (I think it’s now called Outlaw).  Those have the ability to show the terminal output in a window inside their IDE.

There is a way on Windows the console windows opens automatically for you.

Thank you Rob. for the “Terminal”

I’m still wating for help on the previous problem (see two comments up please"

My friend told me that I have to pay $2 500 per year each year to have an app on the app store, using corona , is that true?

Hi Victor,

Certainly not! :slight_smile: Corona Starter is absolutely free… you don’t need to pay us anything to publish to the App Store, Google Play, or any other marketplace. You don’t even need to include a Corona “splash screen” in your app.

The price you heard might have been for Corona Enterprise, which is a high-level service that allows you to create and integrate “native” code and features in other languages and use them along with Corona. That comes at a price of $2499 for large studios and $999 for smaller studios.

The pricing page shows the details: http://www.coronalabs.com/store/

One price you must pay is for an Apple Developer License. This is $99 per year, and it’s required to publish to the App Store. See this guide on more about that:

http://docs.coronalabs.com/guide/distribution/iOSBuild/index.html

Hope this helps clarify it. :slight_smile:

Brent

Thank you Brent!

I’m going to trust you, instead of my friend, because I really like Corona.

But I still need the answer for some of the problems I have to make my app. I want to make an educational app for children, if you put my name in google you’ll see that I have 24 books published already with Hal Leonard and Mel Bay.

I need to be able to put sound on an app, is it that complicated?

Where is the iPad simulator in Corona, everything I have seen is on the iPhone.

I need to make use of storyboard to create a book with many pages, about 100 is it possible?

I need to move an object in response of an event, how do I do that?

Is there any school, near Murrieta, Ca. where I can learn Corona?

I know, I have a lot of questions, please help me out, I’m very interested in creating these apps.

Thank you Brent.

Victor

Hi Victor,

I’ll try to answer your questions in turn:

  1. Adding sound to an app is relatively simple in Corona. You can do it “manually” using the audio APIs (http://docs.coronalabs.com/api/library/audio/index.html). Or, if you really want a simple method, some users really like the “GGSound” library, which is available here: https://github.com/GlitchGames/GGSound

  2. To view the Corona Simulator in “iPad” mode, go to Window > View As > iPad.

  3. Storyboard scenes are basically “unlimited”. Create as many as you need, but don’t load all of them in to memory at one time.

  4. This guide should help you with events: http://docs.coronalabs.com/guide/events/detectEvents/index.html

  5. I don’t know any physical “schools” in your area, but you can purchase a book about learning Corona. There are many options available here:

http://www.coronalabs.com/resources/books/

Hope this helps!

Brent

I try the CGSound:

I got this…

File: module ‘CGSound’ not found

Module ‘CGSound’ not found:resource (CGSound.lu) does not exist in archive
    no field package.preload[‘CGSound’]
    no file ‘/Library/Application Support/Corona/Simulator/Plugins/CGSound.lua’
    no file ‘/Users/victormbarba/Desktop/CORONA/iceCave/CGSound.lua’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/CGSound.lua’
    no file ‘/Library/Application Support/Corona/Simulator/Plugins/CGSound.dylib’
    no file ‘./CGSound.dylib’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/CGSound.dylib’
 

My code is this:

local CGSound = require (“CGSound”)

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

sound:add (“sound.wav”, “sound1”)
sound:setVolume ( 0.8 )
sound:play (“sound1”)

Please help me, I’m going to try the other one

Should be “GGSound” correct? Not “CG” ?

In the other one I just don’t understand what do I have to look for,  I see a lot of information, all this

Functions
audio.dispose()

audio.fade()

audio.fadeOut()

audio.findFreeChannel()

audio.getDuration()

audio.getMaxVolume()

audio.getMinVolume()

audio.getVolume()

audio.isChannelActive()

audio.isChannelPaused()

audio.isChannelPlaying()

audio.loadSound()

audio.loadStream()

audio.pause()

audio.play()

audio.reserveChannels()

audio.resume()

audio.rewind()

audio.seek()audio.setMaxVolume()
audio.setMinVolume()

audio.setVolume()

audio.stop()

audio.stopWithDelay()

Is there any sample code somewhere just to copy and paste, I just want a button to play a sound.

if I have to read all these it will take me a long time, and I don’t even know what should I read first

I don’t have a lot of time in my life, I’m 52.

Please I’m sorry if I ask you a lot of questions, I just want to make an app before I die.

I try the GGsound

I have this

Module ‘GGSound’ not found:resource (GGSound.lu) does not exist in archive
    no field package.preload[‘GGSound’]
    no file ‘/Library/Application Support/Corona/Simulator/Plugins/GGSound.lua’
    no file ‘/Users/victormbarba/Desktop/CORONA/iceCave/GGSound.lua’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/GGSound.lua’
    no file ‘/Library/Application Support/Corona/Simulator/Plugins/GGSound.dylib’
    no file ‘./GGSound.dylib’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/GGSound.dylib’

My code is this

local GGSound = require (“GGSound”)

sound:add (“sound.wav”, “sound1”)
sound:setVolume ( 0.8 )
sound:play (“sound1”)

local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

Why is that sooooo dificult just to play a simple sound?
 

Hi Victor,

GGSound is about as simple as it gets. Did you follow the specific directions along with the module? Did you put the module file in your project directory, exactly where it instructs? Have you included the sounds that you’re trying to load and play, in the location they’re supposed to be?

Of course, you can do this directly using the Corona audio APIs as I mentioned before, which is what many people prefer… but for pure “ease of use”, GGSound is really useful.

Brent

I told you Brent, I’m “really” new at all this. Sorry.

Brent: Did you follow the specific directions along with the module?

Victor: What directions?, Where do I find the directions? Which module?

Brent: Did you put the module file in your project directory, exactly where it instructs?

Victor: I think my “project directory” is a folder that I have in my desktop, where I have the main.lua file and all my .png and sounds, is that the directory you are talking about? When you say Directory is the same as a folder on my desktop?

Brent: Have you included the sounds that you’re trying to load and play, in the location they’re supposed to be?

Victor: I only have one sound to test. it’s “sound.wav” and I have that inside the same folder where I have the main.lua file and all of my images, is that where the sound supposed to be?

Brent: you can do this directly using the Corona audio APIs

Victor: What is APIs?

Sorry for all this Brent, but believe me, I will learn and I will have my app in the app store, I really appreciate all the time you’re spending in teching me.

Now you see I have many questions, that’s why I wanted a video where can tell me in a simple way how to play a sound, but from the very beggining, not assuming that I already should know something.

As for the books you told me, I have 4 PDF files in my computer that I have been trying to study and read, but THEY ALL ARE FOR MORE ADVANCED PROGRAMMERS, they are speaking in a language I don’t really understand, I need to star from the very bottom. WHERE DO I DO THAT? or HOW?

Victor

Hi Victor,
No worries, we all start from the beginning at some point. :slight_smile:

When I refer to “module”, it means an additional “library” which is added to Lua/Corona. It is basically just an extension added to your project, like if you added a high-end stereo system to a car. The GGSound library is like that, and there are countless other examples, both native to Corona and written by other developers.

The “project directory” is what you say… the folder where you have main.lua and other essential core files.

Here are a few more guides which can help:
http://docs.coronalabs.com/guide/start/helloWorld/index.html
http://docs.coronalabs.com/guide/start/displayGroups/index.html
http://docs.coronalabs.com/guide/media/displayObjects/index.html

Any of the “beginner” books or eBooks on the site I mentioned should help you understand Lua/Corona from the beginning. The prices are very reasonable… between $5 and $35 generally… and they’ll really help you start on your path to become a master developer. :slight_smile:

Brent