Feb 122011
 

This tutorial will show you how to change the way a button in your iPhone app looks while it is being touched.

This is a very basic sample project written in the same style as my Corona For Newbies mini-series, (I promise I’ll write part 3 soon!) and should be very easy to follow for anyone, even those who have only just picked up the Corona SDK.

The file is a tiny download consisting of the standard, build.settings, config.lua and main.lua and three images – so I wont bother putting the code into this blog post as it seems unnecessary.

You will be able to put a button in your app and have it change it’s image when touch is pressed down on it, just like most buttons on your screen right now would do. (On other websites. I’m lazy and Techority isn’t one of your fancy tutorial websites.)

DOWNLOAD THE PROJECT HERE

Enjoy!

Peach Pellen :)

Sidebar: A brief sidebar regarding the Techority hiatus/my health; I do now plan to update the site slightly more often although I wont be doing a post every day or two as I was for awhile there. Ideally I can do maybe two a week.

I’m still meant to be resting a lot as many of my symptoms, while not caused by overdoing it are apparently exasperated when I spend any significant amount of time working. That will pass, but I do still need more time off.

On a more personal note still, while the diagnosis will not be “official” until yet another series of tests next week it appears I have a very uncommon disease effecting the vascular system. (Tests are required to work out what variety I have, given that there are about 12 different kinds.) However, if this is indeed the case having sought medical attention early, (I will begin treatment next week,) there is a very good chance that it could go into remission – this is what I am hoping for.

Lastly, I would like to thank all of you who have donated during this period; I’m well aware for most of you it has been out of sympathy rather than because I’ve written some fabulous new tutorials, and I appreciate that.

Malnutrition is something which, I learned only yesterday, can cause symptoms to flare up – mine have not been that bad this past week and I attribute that entirely to the donors; thanks to you guys last night was the first potato meal I’d eaten in weeks. Fantastic!

Also, an extra thanks, as I was able to fill my prescription the day I got it (to help with my symptoms, not the condition) from donations alone. This is obviously a huge deal to me as managing symptoms well will alleviate most of the associated angst/depression associated with trying to deal with this issue.

Thank you all.<3

Like this post? Subscribe to the monthly newsletter!

 

  8 Responses to “Mouse Over Button Effects In Your iPhone App”

  1. The functions and listeners are a little different as you can see from the code compared to a “normal” button, yes.

    Your error will depend on your code; these buttons can be used fine with Director or Storyboard.

  2. Hey Peach,

    Thanks for the tutorial :)

    If I create this is a basic app like you did it works for me, however, if I try and put this into my menu with the director class I get a runtime error whenever I load the application. The button was an image before I made it into a ui.newButton and attached to it was an event listened to change scene upon a a touch. For some reason this doesn’t work if I use ui.newButton rather than an image. Do you have to code functions/event listeners different for these?

    Thanks for any help :)

    Alex

  3. Hai

    This is very helpful to me to learning to corona and lua thanx for this tutorial

  4. Hey Jon,

    I’m very pleased that my tutorials have been helpful for you, although I am sorry that there aren’t more; the site is not that old, yet.

    First up – for your resolution independence – download this; http://developer.anscamobile.com/code/ghosts-vs-monsters

    That’s Ghosts Vs Monsters made by Jon and Biffy Beebe – just check out how they do resolution independence if the proper Ansca pages on it are confusing.

    Second – I can’t say for sure whether or not it will work perfectly as it is not something I’ve done in that way. (I have a very specific way of doing things and rarely stray from that.) However in theory I suppose it should; see if you get any errors thrown up in terminal, perhaps, and let me know?

    Last – Yes, one or two other files are often dropped in. For example if you use Facebook or OpenFeint a file will be added during the build process – however for things like director you add the file first. (You’ll get used to this, you don’t add files that often and it will become second nature quite quickly.)

    I hope that helps!

    Peach :)

  5. Thanks for this little tip.

    I’m trying to get into Corona, keep hitting big massive giant walls of confusion. Your tutorials are a god send, just wish there were more.

    I’ve started piecing together what is a simple sound board app, I want to build it from scratch rather than use any templates. I’m also trying to build it with resolution independance built in so it works for all devices.I have only just got images displayed using ‘display.newImageRect’ with different sized images saved in an images folder.

    Will the method described here work for that?.

    I’ve been using code like:

    1
    2
    3
    4
    5
    6
    7
     -- Listen to an event
    local function button_pressed (event)
          local snd_button1 = display.newImageRect( "images/button_down.png", 140, 42)
               
            button_pressed:addEventListener("touch", snd_button01)

    end


    Also… is it the norm in Corona to grab extra pages of code like the ui/lua file rather than making things yourself entirely from scratch. As I’m really trying to understand why everything does what it does so I can eventually write lines of code confidently.

  6. Hey Peter,

    Yup, that’d be me – it’s not the best picture but it’s the only one I had on my computer at the time that seemed an alright size to use for a button; that was back when I did my first tutorial. Now it’s the default I use every time :)

    Peach

  7. Just wondering if you are the girl of the pic :)

 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.