MovieClip Button Library (stable alternative to ui.lua) Handy for director class

Are you sick of ui.lua ? Sick of it with director class? Here is the answer!

I was tired of ui.lua making my code slower and unstable so created the MovieClip Button library.

It uses movieClip.lua and supports the same button types as ui.lua (button pressed, button released).

However! it doesn’t stop there.

Here are the supported features :

  1. Each button can have it’s own unique sound effect.

  2. The button’s touch listener is removed after successful execution of the button press. This prevents crashing and code from getting executed more times than it is supposed to.

  3. The library handles everything for you so you only have to set up a few variables and the rest is done.

  4. Each button can have its own custom function executed for “began” and “released” states.

Example usage :

Please see included samples (screen1.lua or screen2.lua) or continue reading below

  
In your main.lua file include these lines :   
  
local movieclip = require("movieclip")  
uiButton = require("buttonLib")  
  
Then you set up buttons like so :   
  
 newGameBTN = movieclip.newAnim({"newGame.png", "newGame2.png"}) -- The sequence of images : Should contain a default and pressed state image  
 newGameBTN.x = display.contentWidth / 2 -- The x position of the button  
 newGameBTN.y = 140 -- The y position of the button  
 newGameBTN.sound = clickSND -- The pointer to the button sound effect (each button can have it's own unique sound effect  
  
 --The Two below variables are not required if you are not using the director class  
 newGameBTN.sceneChangesTo = "screen2" -- The required scene to change to on touch  
 newGameBTN.sceneChangesWithEffect = "moveFromRight" -- The required effects to apply to the scene change  
 newGameBTN.beganFunction = newGameBeganFunction -- The pointer to the custom function to execute on button began state (If any) Optional  
 newGameBTN.releasedFunction = newGameReleasedFunction -- The pointer to the custom function to execute on button began state (If any) Optional  
  
 localGroup:insert(newGameBTN)  
  
 --Add the event listener for the button  
 newGameBTN:addEventListener("touch", uiButton.handleEvent)  

After that the library handles everything else for you.

Download it here : www.infuseddreams.com/demo/ButtonLib_V0.1.zip

(I will submit it it the codebase, however i get an error : Compatibility: illegal value.) Isn’t it just the build number that is in there ? ie : 243 ?)

If you like it or need help using it, please leave a comment! [import]uid: 6981 topic_id: 6986 reply_id: 306986[/import]

Edit : Just released v0.2

Changes :

Fixed a bug.

Realized that you may not always want to remove a button listener straight after using it (say in a options menu) so you can now specify if the listener should get auto removed upon touch. If not you can remove the listener yourself (in a back button listener for instance)

syntax :

removeListenerOnTouch

usage :

newGameBTN.removeListenerOnTouch = true – If true the library will automatically remove the event listener for you when it is done.

Download the new version here : www.infuseddreams.com/demo/ButtonLib_V0.2.zip

the new code and sample is also part of that archive along with usage sample
[import]uid: 6981 topic_id: 6986 reply_id: 24481[/import]

Edit : Found one minor bug that is now fixed.

The library is bug free now from my testing. If anyone has any issues please report them here.

Download link : www.infuseddreams.com/demo/ButtonLib_V0.3.zip

Thanks [import]uid: 6981 topic_id: 6986 reply_id: 24536[/import]

I can’t get your lib, HTTP 404 msg [import]uid: 28742 topic_id: 6986 reply_id: 24614[/import]

Hey.

Sorry I just took the link offline while i tested thoroughly on the device as well as the simulator.

Just want to be 100% certain it is bug free. Seems like it is working great now, just doing some final testing to confirm then the download link will be back :slight_smile:

Edit : It passed the testing and is now available to download again. If you downloaded a previous version of this library please discard it and download the new version here : www.infuseddreams.com/demo/ButtonLib_V0.4.zip [import]uid: 6981 topic_id: 6986 reply_id: 24671[/import]

Sounds interesting!

I would like to see a better API for this. Something more standard, like:
[lua]button = buttonLib.newMovieButton{
images = {“newGame.png”, “newGame2.png”},
x = display.contentWidth / 2,
y = 140,
sound = clickSND,
scene = “screen2”,
effect = “moveFromRight”,
beganFunction = newGameBeganFunction,
releasedFunction = newGameReleaseFunction }
localGroup:insert(button)[/lua]

Just something more like what people are already used to doing in Corona.

Also, not sure why you break the Began and Released functions into two calls rather than using the standard event handler syntax. Again, making this more like normal Corona code would be nice.

I actually use a ui.lua that I modified myself to also include the button Width and Height properties. I like to use display.newImageRect(image,w,h) to load images so that I have better support for different device resolutions. This lets Corona load high resolution versions of the buttons for iPads or Android HD devices. So that’s something else you might want to consider.
[import]uid: 12529 topic_id: 6986 reply_id: 24697[/import]

Yeah I guess I didn’t have to break it down into two functions…

I will take your suggestions into account :slight_smile: [import]uid: 6981 topic_id: 6986 reply_id: 24710[/import]

Version 0.4 works nice in my app with Sprite Deck, Director class 1.2 and all my craziness thats I’ve got going on. Great work!!

[import]uid: 33866 topic_id: 6986 reply_id: 24723[/import]

Thanks :slight_smile:

I may add more functionality to it or change the syntax, if enough people are interested.

Glad you like it [import]uid: 6981 topic_id: 6986 reply_id: 24732[/import]

+1 for the #5 reply of MPotter [import]uid: 11749 topic_id: 6986 reply_id: 24897[/import]

Hi,

Can’t get the zip archive, the server returns a suspended page message.
Where can we get it now?

Thanks.
Ch. [import]uid: 4958 topic_id: 6986 reply_id: 25575[/import]