How Can I Add A Sound To A Button

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

Hi BRENT!

I’m back… (I know, sorry)

I’m reading Dr. Burton’s Book, it’s really good, BUT I DON’t see anywhere HOW TO CHANGE THE PAGE.

I have a book, one page only (main.lua) I can do a lot of nice things in just ONE PAGE or one view or one file, I don’t know the correct name.

now I want to go to another page in my book, or another scene, or another view.

Would you please tell me how to do that?

Thank you Brent

Victor

Testing: I just want to see If I can add a video here

https://www.youtube.com/watch?v=9u21eSR4O1E

IT WORKS!!!

Now I can explaing things better, GOOD!

Hi Brent, Thank you.

The Hello World was really good! I learned a lot there, I got it – Checked!

The Cartesian coordinate system I got it I understood that, good! – Checked!

– PROBLEM

The problem was with the parents, and children, and siblings and all the family…

I did not really get the “myGroup” thing this is the code


local stars = display.newGroup()

local redStar1 = display.newImage( stars, “redstar.png” )
local redStar2 = display.newImage( stars, “greenstar.png” )
local redStar3 = display.newImage( stars, “redstar.png” )
local greenstar = display.newImage ( stars, “greenstar.png”)

local whiteStar1 = display.newImage( stars, “whitestar.png” )
local whiteStar2 = display.newImage( stars, “whitestar.png” )

–insert only the red stars into a table
local redStars = { redStar1, redStar2, redStar3 }

for i = 2, #redStars do
    --manipulate the star at the current index (i)
    redStars[i].x = redStars[i].x + 100
    redStars[i]:scale( 0.4, 0.9 )
end


I just see images in the simulator, but I don’t really understand what to do with them!

And I still can not have sound on the app. Even though you said it was so simple, I still don’t have sound in the app

I know it may look like imposible to believe, but it’s true, please help me out with that.

I’m going to buy a book that you said, but I really need help with the sound

Victor

Hi Victor,

On the “GGSound” module, the basic setup is like follows (this is similar to most “libraries” or “modules” that you add on to the project, including many bundled as part of Corona, and also 3rd-party libraries like GGSound).

  1. Download the GGSound.lua library (https://github.com/GlitchGames/GGSound)

  2. Place that file inside your project directory.

  3. “require” it in “main.lua”. This essentially tells Lua that you want to add that library as an external element of your code. Do this near the very top of your main.lua file!

[lua]

local GGSound = require( “GGSound” )

[/lua]

  1. “Reserve” some audio channels in Corona. Corona’s audio system has 32 available audio channels. This allows you to control the volume of certain channels independently, i.e. if you want music to play at one volume and sounds at another volume. Unless you tell a sound to play on a specific channel, the system will automatically choose an open channel and play the sound on it… there’s no need for you to seek an open channel in most cases. Anyway, for our example, let’s “reserve” channels 1-3 for these test sounds.

[lua]

audio.reserveChannels( 3 )

[/lua]

  1. Initialize the GGSound library with a local variable named “sound”. The “1, 2, 3” part tells GGSound to play the sound only on those channels we reserved in the previous step.

[lua]

local sound = GGSound:new{ 1, 2, 3 }

[/lua]

  1. Load a new sound into the system. Notice that sounds have “handles”, which is essentially a name which you refer to it by… in this case, “sound1” is the handle.

[lua]

sound:add( “sound1.wav”, “sound1” )

[/lua]

  1. Adjust the volume if needed, between 0.0 and 1.0

[lua]

sound:setVolume( 0.8 )

[/lua]

  1. Play the sound by putting in the “handle” from above.

[lua]

sound:play( “sound1” )

[/lua]

That should do it!

Brent

Hi Victor,

The official supported scene management for Corona is Storyboard. I’m not sure if Dr. Burton’s book has a chapter on that, but you’ll need to learn how to use it eventually.

http://docs.coronalabs.com/api/library/storyboard/index.html

It’s not exactly “difficult” to learn, but I suggest that you continue with other topics before you attempt this. A solid foundation in Lua and Corona should be established before you attempt scene management.

Brent

Hi Brent:

THANK YOU, THANK YOU, THANK YOU, …Yes!

Now I have sound in my app!

I’m going to keep working hard, I have two or three things to practice.

– NEXT QUESTION

How do I make a button, play the sound.

Because now the sound plays as soon as I start the app, but I want to have a button, and when I touch it, the play the sound.

– NEXT QUESTION

And can you tell me as simple as you did with the sound code, a code to work with storyboard? I want to write my book with many pages.

Thank you one more time Brent.

Victor

Buttons don’t play sound. Buttons (like all the widgets) do have listeners. A listener is a method that is being called when a certain action happens. Like the button being released. I’m not sure if you already have an understanding for these abstract interactions between objects in your game. No worry, it takes some time, but if you understand you will be able to use new features much more quickly.

Now, in the API docs for newButton you can see one parameter called onRelease 
http://docs.coronalabs.com/api/library/widget/newButton.html

So, what you need is first a function that plays a sound. Secondly you need to create the button and use the name of that playSound function as a parameter for onRelease. Go on, let’s see if you can adapt the button example from the API without help :slight_smile:

PS: Playing a sound on touching (pressing) a button is a bad idea, even your computers browser will only execute an action on releasing the button. try but pressing then moving away from the button before releasing. nothing should happen.

Thank you info4307.

I made two buttons and they play a different sound each GOOOOOOOOOOOOOOOOOOODDDDDDD!!!

Finally, you can look at the very top of this document, Finally I got it!

THANK YOU!

I don’t know if this is the “correct” way but it works!

– THIS IS MY CODE

local GGSound = require (“GGSound”)
audio.reserveChannels (3)

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

--------------------------------------------------------------CREATE A BUTTON------------
local piranaPlay = display.newImage( “pirana.png” )
piranaPlay.x = display.contentWidth / 2 – This is just to position the image pirana on the x horizontal
piranaPlay.y = display.contentHeight - 100 --This is for the vertical position y
-----------------------------------------------CREATE A FUNCTION TO MAKE THE BUTTON WORK–
function piranaPlay:tap( event )
    local sound = GGSound:new {1, 2, 3}
    sound:add (“c.wav”, “c”)
    sound:setVolume (0.8)
    sound:play (“c”)    
end
---------------------------------------------------------------CALL THE FUNCTION----------
piranaPlay:addEventListener( “tap”, piranaPlay )

– NOW, let’s keep going

I look at the widget link for buttons you sent me.

By logic I think it might work the same as the “require” GGSound

I had to go here (https://github.com/GlitchGames/GGSound)

to download the file GGSound.lua and then place that file in the folder I want to play the sounds.

in the code for the button I see:

local widget = require( “widget” ) – I THINK I have to have a file “widget.lua” in my folder to actually make a button using that widget correct?, and if so, the question is…

where can I download or copy that file?

So far everything looks good I’ll work on that and I will have more questions.

THANK YOU,

I’m really happy now.

Victor

Hi 

helloworld2013d,

​From what Ive read, yes we all do start from the beginning. But what you seem to be doing is trying to get everything you need on a spoon! Congrats on your books, but all beginners have to go through a LEARNING curve, which you seem to want to bypass!

Hacking together basic code is not the way. Please take some time to read some basic tutorials, (which would for example tell you HOW sound in Corona works, rather than posting 100 questions to every NEXT step…

I am a beginner, but Im also going through the motions and trying to learn on my own…you are simply trying to get everything you need, without any research.

Im trying to help, as if you continue like this you’re going to have problems once your work gets complicated, ive seen it so many times, with no foundation, it becomes harder to debug later, and then you become COMPLETELY reliant on forums.

Heres an EBook i bought and downladed, its very good, and No you dont have to read from beginning to end. but its Organised into Key features like SOUND, PHYSICS, ANIMATION etc, which you can flip to, have a quick read and most importantly UNDERSTAND what youre supposed to do, instead of hack slashing libraries together.

Hope this helps.

http://www.burtonsmediagroup.com/books/mobile-app-development-with-corona-getting-started/

Cheers

Jack, in general I agree with you, but Victor at *least* appears to be willing to keep trying things to try and make them work. That’s very different from a lot of newbies I’ve seen. :slight_smile:

Victor, yes, based on what you did with GGSound, you’d think you would also need a widget.lua file, but that’s actually built into Corona SDK. The line:

widget = require(“widget”)

…is basically just telling Corona that you’re going to be needing the widget library and so to have it ready. You don’t need an external file to use widgets.

Yes, it can be kind of confusing at first as far as what’s included and what you need to add, but you’ll get the hang of it.

 Jay

Oh, and Victor, when Jack said, “…you’re going to have problems once your work gets complicated…” he was right on. Corona SDK makes some things so easy you can cobble things together pretty easily. But you can also build a house of cards that will tumble down at the first gust.

So you’re headed in the right direction; just don’t think you need to floor it the whole way. You’re only 2 years older than me so you probably have time. :wink:

Jay

Thanks Jay,

Spot on there. Victor, nothing wrong with getting help, but if all your code is from Forum directed APi’s and links, you start to develop a tunnel vision of code…

If you understand the basics, (for corona, the time taken to understand the basics is not long at all), you can start to see the big picture of your work, so please try and check out the book link i sent you!

Hi Brent!

I think I got it!!!

I can change to another view in storyboard,

I can change with a button that I created with thw widget

I can add more views or levels, and I can go to any level I want.

Saer sent me a zip file with that and a few hours of my time I GOT IT!

Thanks for all your help.

NO Dr. Burton books does not talk about storyboard…


Now I can start making my book!

one question –

How can I make the background image .png fill the entire view in the iPad simulator?

My file is .png 1024 X 768 Landscape, but when I display.newImage the file fills only 3/4 of the screen why?

Victor