Jan 222011
 

I’m proud to present part 2 of Techority’s mini series, Corona For Newbies.

*UPDATED to work with new audio APIs. (February 20th, 2012)

This time we cover sound effects, background music and touch event phases (lightly, sounds and music are what it’s all about this time).

There are only 3 sections to this mini set of tutorials however as so many people requested sound, and it is entirely covered, I think you should all be quite happy.

Part 3 will be created soon so leave your suggestions; nothing too advanced though, we’re taking baby steps to help non coders ease themselves into things comfortably.

As usual, if you appreciate my efforts you can donate a buck or two using the button on the right. (Go on, who doesn’t like buying a nice girl a drink?)

Peach Pellen :)

PS – If you’re as broke as I am and have no money to donate, you can show your love by following me on Twitter and adding me on Facebook – you can also tweet about this post using the button below. Thank you!

Download Corona For Newbies Part 2
Like this post? Subscribe to the monthly newsletter!

 

  87 Responses to “Corona For Newbies Part 2”

  1. can u send the tutorial pls

  2. Yup Audacity gets the job done. Indeed there’s a few milliseconds padding at the end of my loop. Thanks !

  3. Hey Shao, chances are you have a little dead air at the start or end of your track – audacity is a free audio editor for Mac, maybe check that out?

  4. Hi Peach,

    I need to play a repeated loop as a background music.
    I set the loops = -1

    However, the end of the loop and the beginning of the loop doesn’t stick together.
    There’s a gap in between.

    Anyway to connect it and loop it smoothly?

  5. very nice tutorials,thank you :D

  6. I can’t see the tutorial…only the post telling about it. Where is it?

  7. Alright, let’s cover this point by point :)

    1. Commenting this out can be done with –[[ at the start and --]] at the end. If you’re using a proper editor commented text looks different to uncommented text. (It changes color.) Is that happening?

    2. iPhone4 stuff is to do with config.lua I believe – can you post your entire config.lua file here and I’ll try to assist with it? (I’ve seen this before, plenty of times.)

    3. Dragging and popping back – I can’t see why that is happening. Can you upload your project file somewhere so I can take a look and try to advise you?

    I appreciate the donation and use of the words “ducats”, haha :)

    Thank you too for the kind words.

    Peach :)

  8. ooh, the iPhone doesn’t like that 640×1000 pixel file. It crashes the app
    I took a look at the menu page and its 320×480 and it isn’t squished like the recipe1.png file which originally was 320×1000. Do you know of a reason, since the code is above, why the 320 would get squished to a 3rd of its size?

    Thanks,
    Richard

  9. Ok, I commented out lines of code but they still build into the app.

    –[ starts the commented out line, yes??
    --] ends the commented out line, yes??

    I finally just cut out the events.x&y and topmenubar and finally achieved almost what I’m looking for.

    Also, I figured out that the retina display in the iPhone 4 is shrinking the 320pixel wide recipe into a smaller viewable file.

    I photoshopped it to 640 and it perfectly fills the screen.

    Now the real question…

    The recipe scrolls but I want it to stop where I leave it and not “pop” back to its original spot on the screen.

    Can you point me to a tutorial or do you have a quick solution?

    Correct me now, but does it have to do with the original position of the recipe1.x = 160 and recipe1.y = 230?

    If correct at least something sticking to my brain and that’s kool. Now I guess I have to manipulate that action with some extra simple lines of code and maybe, just maybe an eventListener?

    Beat me with a stick but I think I’m starting, just starting to think via Corona vs. Xcode (I learned from 4 different books for 6 weeks before finding Corona).

    Thanks, Peach. Once I get my PayPal going again ducats are coming your way. You’re the most helpful person I’ve encountered on the net.

    Richard

  10. Haha, good, good.

    The jumping thing – is because it’s the center of the image is the part being moved to event.x and event.y regardless of where the image is touched.

    You have to take the start points into account as well. See this; http://blog.anscamobile.com/2011/09/tutorial-how-to-drag-objects/

    Peach :)

  11. Peach, I feel like I’m burning up your waves here.
    After I posted that last one it was right in front of me. I was using “dragpeach” instead of “dragrecipe1″.
    LOL
    Ok, it worked!!! Whoohoo!!!

    Weird thing though. When I “touch” the image to scroll it it does scroll but also jumps left on a touch, jumps center on a touch and jumps right on a touch. Weird, huh?

    Thanks,
    Richard

  12. Hah! I got it to work!!! I used the “object” “recipe1″ and it made it 1.5 times bigger.

    Ok, I used info from your tutorials and added code for centering the image, scaling of the image and dragging the image.

    The dragging doesn’t work but the centering and scaling do. Baby steps are great achievements.

    Here’s what I’m left with. You’ll probably have a good smile and see my issue immediately.

    Oh, the back button still doesn’t appear on screen and no dragging can be accomplished:

    module(…, package.seeall)

    function new()

    local recipeGroup = display.newGroup();

    local scrollView = require(“scrollView”)
    local util = require(“util”)
    local topBoundary = display.screenOriginY
    local bottomBoundary = display.screenOriginY
    local scrollView = scrollView.new{top=topBoundary,bottom=bottomBoundary}

    local recipe1 = display.newImage(“graphics/recipe1.png”)
    recipe1.x = 160
    recipe1.y = 230
    recipe1.xScale = 2.0
    recipe1.yScale = 2.0

    local function dragrecipe1 (event)
    recipe1.x = event.x
    recipe1.y = event.y
    end
    recipe1:addEventListener (“touch”, dragpeach)

    local topMenuBar = display.newImage(“graphics/topMenuBar.png”)

    local backButton = display.newImage(“graphics/backButton.png”)
    backButton.x = 40;
    backButton.y = 28;
    backButton.scene = “menu”;

    scrollView:insert(recipe1)
    recipeGroup:insert(scrollView);
    recipeGroup:insert(topMenuBar);
    recipeGroup:insert(backButton);

    backButton:addEventListener(“touch”, changeScene);

    return recipeGroup;

    end

    Thanks, Peach.
    Richard

  13. Sorry maybe I wasn’t clear enough; you don’t do newImage.xScale

    In your example above from the recipe app if you want to make an object/image called recipe1 larger, you’d do this;

    recipe1.xScale = 1.5
    recipe1.yScale = 1.5

    Get it? :)

  14. Ok, I thought I caught the mistake but it still didn’t work.
    I used “obj.xScale = 1.5″ and also the ‘y’ but it just made the back button disappear from the page…
    Hmmm…..

    Richard

  15. Oh, I also tried it with “object.xScale = 3.5″ also and it had no effect.
    In the above I referenced the “object” but it was another attempt to have it work with “newImage.xScale..”

    Thanks.
    Richard

  16. Ahh well, I must not be doing it correctly, Peach. Hmmm.
    Here’s the code I’m working with. It’s the Recipes from your site link…

    function new()

    local recipeGroup = display.newGroup();

    local scrollView = require(“scrollView”)
    local util = require(“util”)
    local topBoundary = display.screenOriginY
    local bottomBoundary = display.screenOriginY
    local scrollView = scrollView.new{top=topBoundary,bottom=bottomBoundary}

    local recipe1 = display.newImage(“graphics/recipe1.png”)
    newImage.xScale = 3.5
    newImage.yScale = 3.5

    local topMenuBar = display.newImage(“graphics/topMenuBar.png”)

    local backButton = display.newImage(“graphics/backButton.png”)
    backButton.x = 40;
    backButton.y = 28;
    backButton.scene = “menu”;

    scrollView:insert(recipe1)
    recipeGroup:insert(scrollView);
    recipeGroup:insert(topMenuBar);
    recipeGroup:insert(backButton);

    backButton:addEventListener(“touch”, changeScene);

    return recipeGroup;

    end

    I added the “object.xScale = 3.5″ after the newImage was introduced on the Recipe1 page..

    Thanks,
    Richard

  17. Hey Richard,

    Yes, this is scaling :)

    Do this;

    1
    2
    obj.xScale = 0.5
    obj.yScale = 0.5

    That would be half size. 1.5 would 1.5x the size.

    Peach :)

  18. I have a need to stretch a graphic, or I just need to make it bigger.
    Is this scaling? I’m a newbie for sure and I’m really digging your tutorials.
    They rock!

    Got any assistance or a tutorial that I’m overlooking?

    Thanks,
    Richard

  19. hi, i was just wondering why there are two “end”s after the play ouch function. i deleted one of them and saw the whole screen turn black, but i am not exactly sure why.

    thanks

    andrew friday

    • Hey Andrew,

      That is because there is an if statement. If you use “if X then” you need an “end” on that as well. I could have used “tap” rather than “touch” and removed the “if X then” and 2nd “end” altogether but I was fairly new when I wrote this and I think “tap” may have had some issues at the time.

      Peach :)

  20. Hi Vanessa,

    I am sorry, I do not speak Spanish! I can only understand very little of what you are saying.

    Can you try here? http://developer.anscamobile.com/forums/corona-en-espanol

    Peach :)

  21. estoy haciendo un comic y lo que necesito es asignarle que se dispare la musica cuando este en una determinada pagina, y asi con varias paginas con dif musica. Eso se trabaja mas bien con escenas (scenes) pero el tipo de animacion del comic no lleva scenes, no tengo archivos de codigo por cada escena sino todo en un archivo de coordenates.lua donde asigna que parte se ve en cada page().png y se activa a traves de la orden de un reader.lua que indica que se tiene que ir pasando con el dedo pagina por pagina. Por favor me podrian ayudar a hacer esto. desde ya muchas gracias!

  22. Hi Peach, whats the difference between media.playEventSound and media.playSound? and you didnt assign a variable to the media.playSound(“gamemusic.mp3″) how come? could u have?

  23. No worries, good job on figuring it out :)

    Thanks for sharing!

  24. I went back on Coronas website and figured it out. They did change the API for sound. The new code to play audio is
    audio.loadsound() — load sound into the app
    audio.play() — play sound in app

    Here’s the code that worked for me

    - New project using new Corona SDK API’s for sound playing.

    local background = display.newImage (“background.png”)
    – We load up a background image.

    local peachpic = display.newImage (“peach.png”)
    – We load up our peach image.

    ouchSound = audio.loadSound (“ouch.wav”)
    – Load up the audio into our app.

    local function play (event)
    if event.phase == “ended”
    then
    ouchSoundPlay = audio.play (ouchSound)
    end
    end
    – call the function to play the sound only once per click then end

    peachpic: addEventListener (“touch” , play)
    – Listner to trigger function

    Sorry code is messy.

  25. Hey Yuri,

    I previously thought this was a Windows issue however the Corona audio API has changed, so I need to take a look into changing the old tutorials ;)

    Peach

  26. Hey peach I love the tutorials and really want to get started in app development just for the fun of it but im having an issue with this music tutorial here.
    It seems that the sound only plays once after I launch the main.lua file in the simulator. I have to relaunch every time to play the sound again. Please be advised that I am running this on a Windows 7 machine as I don’t have a mac yet.
    Im thinking the code may be good but the simulator is running weird cause of Windows. Or does this happen to everyone?

  27. Hey Russell,

    Yes, I think it might be to do with Windows/Android as all of these were originally done for Mac. (Some other Windows users have shared similar issues.)

  28. Hi, in lesson 3 the game music would turn on when i clicked on the picture. But it wouldnt turn off when i clicked on the reset button. I wonder why? Could it be im using windows xp. I did not alter the code.

  29. Hey dhavalbhatt,

    I can’t, no. I haven’t played that sort of things and don’t actually know if it is possible to adjust a normal image’s brightness – only its transparency.

    Also, as you can see, this post is about sounds and not images :)

    Peach

  30. hi

    can u help me how can I increase or decrease the brightness of any Image in corona

  31. Thanks again for the tutorial! :)

  32. Within a week or two part 3 will be ready, so long as I am up to it :)

    Thanks for the kind words!

    Peach

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.