How Can I Add A Sound To A Button

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 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 jacksparrow and J.A. Whye.

I just wanted to say thank you to both of you for your advises.

I wanted to make apps, just like my books, to help people to learn something while they play.

I had no idea at all, about one month ago.

I took 7 courses on Lynda.com (HTML, CSS, CSS for developers, javaScript, iOS developers, Programming with Objetive-C, iOS essentials) I did not understood at first. (A lot of new words to me “Instance”“arguments”“call a fuction” etc) when you already know something is so easy…

I have tried to read something on Xcode in the developers guide, it’s so difficult I just don’t understand anyhting. I have 5 PDF that I download, they all think you already have to know something, and where is that something?

I called UCIrvine, ATT instute, The arts institute, San Jacinto College, even UCLA for summer lessons, and nothing, they don’t even have that program to learn how to make an app.

I have watched more than 100 videos on youtube, I have learn some from there, but I just have a little bit here and a little bit there, The programming books, all they say is how to create a fuction, or how to name a variable, or how to make a switch or a if statement, but they don’t give you real life examples in how to apply the knowlage.

I will see the book you reccomend me, thank you for that, and believe me I don’t want to be all over you and asking how do I turn on the computer. But I’m trying so hard to UNDERSTAND how THINGS WORK, and use THE LOGIC for all these.

I have learned a lot I would think, for just ONE MONTH on this new world.

By the way I already got the sound problem resolved, now I need to make the FAMOUS storyboard make it work!

Thanks for everything

Victor

Victor,

after that message, and even before that message we are here to help. Very inspirational to see ho hard you are trying indeed! so you have the right attitude and thats all that matters.

This book takes you from the begining and is very easy to read, as i said all the chapters categorised. However, its also important to have a vision, so you dont learn things you dont need.

Although the exposure is good from your first 7 courses, (HTML, CSS, CSS for developers, javaScript, iOS develo… etc) these are usually very difficult for someone without a background in programming, but nothing you do is a waste, even if it opened your eyes to a little bit of this new world.

heres my advise, especially since i have a degree in Computer Science (hons).

Lua, the language corona is using now, is the BEST for you to start with. dont focus anymore on those other courses. SOmetimes you have to cut through the forest to find the gold.

Read the ebook link i sent you, its not that expensive as an ebook, but the value is great, its very easy to read, very clear, and has specific chapters that you want to know about.

You have done well so far. But If you keep going, your work will get too complicated for you to be able to control or debug later.

Stop for a while, and get this book, and give it a good read, read the overview, pick some chapters that apply to you and get a feel, it explains topics nicely. that will give you a vision, as to what you want to do.

I am a working SAP developer in South Africa, I have a day job, but because i support siblings, ive taken up Corona app development to release my first game to make some money, Even though Im desperate to do it NOW and release ASAP, i know I have to read and understand, it will make it easier once you sit down to code, you will know what you’re doing, and will save you time from posting in forums and waiting.

From what ive read you want to make Interactive digital Ebooks with animations that tell a story?

If this is your situation - there is a 3rd party app that Built just for COrona called KWIK. It can bring your books to life without code or WIth code - works with corona - check it out

http://www.kwiksher.com/

Hope this helps. Keep going, you are not alone :slight_smile: we are all in the same boat!!!

Good luck, feel free to ask questions!!

Thank you Jacksparrow:

One question, once I finish the app in Corona (Because I will finish it) Do I have to pay a membership or a fee to corona to have the app on the apple store or android? and if so, how much do I have to pay a year? or a month? is it like a web-site that I have to pay a hosting fee? please let me know how this work, and I already bought the book, I’m going to start reading it.

As for kwiksher… I really like that, I just need to put photoshop on my mac first, but I really like that program.

Thanks.

Victor

P.S. let me know about the app you are making, good luck with that!

Hi Jacksparrow I just paid the book with paypal. $29.99.

They sent me to another page – redirect

and nothing, the server was not found!

it took me to a clod servise or something,

Now I don’t have the book, And I don’t have the money!

now what?

Hi Victor,

Did you buy Dr. Brian Burton’s book? He’ll be happy to fix whatever happened to your order. Please contact him directly at:

DrBurton [at] BurtonsMediaGroup [dot] com

He’ll resolve this right away and send you the ebook. :slight_smile:

Brent

Hi Brent:

I sent this to Dr. Burton

Delivery to the following recipient failed permanently:

     DrBurton@BurtonMediaGroup.com

Technical details of permanent failure:

Google tried to deliver your message, but it was rejected by the server for the recipient domain burtonmediagroup.com by smtp.secureserver.net. [72.167.238.201].

I guess I got the wrong e-mail

I wanted to buy the book that Jacksparrow told me, I pay to paypal, and NOTHING!

I just know that I will make my app, I just know that, even if is the last thing I do on earth, I will…

Thanks for all your help, I will put your name in the credits in my app to thank you for all you do.

Victor

Hi Victor,

I just contacted Brian Burton, and there was a slight issue with his web server. Can you please contact him again with your request (and information so he can track your order). He’ll fix this right away, send the book to you, and you can start learning Corona the “proper” way. :slight_smile:

drburton [at] burtonsmediagroup [dot] com

Brent

Hi Victor,

I’m sorry you had problems! 

You should have received an email with the download link, even if the page load failed.

The problem on reaching me was the URL in the email address: should have been burtonsmediagroup.com

I just checked my system and paypal. It doesn’t look like you were charged or that the order was processed.

If you want to contact me directly, I’ll be happy to work with you to complete the purchase.

My personal email is DrBurton [at] BurtonsMediaGroup.com

Also, you might consider my new book since you are very new to programming: http://www.burtonsmediagroup.com/books/learning-mobile-application-development/

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 Dr. Burton

I just wrote an e-mail and look:

Delivery to the following recipient failed permanently:

     DrBurtons@burtonsmediagroup.com

Technical details of permanent failure:

Google tried to deliver your message, but it was rejected by the server for the recipient domain burtonsmediagroup.com by burtonsmediagroup.com. [173.254.22.48].

The error that the other server returned was:

550 No Such User Here

It looks like it’s almost impossible to get to your e-mail. I know technology is very dificult

I have 4 e-mails you can contact me any time:

victortvcityads@gmail.com

helloworld2013d@gmail.com

californiamusicconservatory@gmail.com

victorbarba@easymusicschool.com

I really hope that someday i can read your book, I really want to learn, like Brent wrote – the “proper” way

PAYPAL DID TAKE THE MONEY you can double check with them, you know how they are…

I try to file a dispute, but after 45 min on the phone I got NOTHING, only background music

I guess today it’s a sad day, things are not as good, but that’s okay, I will wait for that book.

I just hope it’s not like a wall paper I order from HOME DEPOT, it’s been 45 days waiting to get a roll of wall paper for my office, and still I DON’T HAVE IT, 45 days just to get one roll of wall paper…

I know…

Anyway Dr. Burton, I will be waiting…

Victor