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 :
-
Each button can have it’s own unique sound effect.
-
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.
-
The library handles everything for you so you only have to set up a few variables and the rest is done.
-
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]