![]() If you do make improvements you think others could use, please share in the comments, or contact me so I can update the library here on the site. As with all Corona code I post on this site, the library is free to download, free to use, and you are free to modify it as you see fit. I hope that my fellow Corona developers will find this unofficial library update to be useful. For example, the following code would pause all active timers with the tag “myTag”. You can pause, resume, or cancel all timers with a specific tag by passing the tag as a parameter.You can pause, resume, or cancel all active timers (unless they have their exclude parameter set to true) by calling timer.pause(), timer.resume(), or timer.cancel() with no arguments.timer.pause(), timer.resume(), and timer.cancel() still work as before, but with the following new features:.Timer.performWithDelay(1000, myFunction, 1, "myTag", true) As an example, the following code would create a timer with the tag “myTag” that is excluded from non-specific pause, resume, or cancel calls:. ![]() These new arguments can be added in any order to the end of any existing timer.performWithDelay() call.Timers that are mission-critical and should always run should have their exclude parameter set to true. exclude is a boolean (true/false) parameter that, when set to true, excludes the timer from being impacted by timer.pause(), timer.resume(), or timer.cancel() calls that do not specifically target it by passing the timer’s handle or tag.tag is a string that appends a tag to the created timer that can be used to pause, resume, or cancel all timers with the same tag at once.timer.performWithDelay() now accepts two new optional function arguments: tag and exclude:.But you also gain access to these new features: Note that your existing code will continue to work – version 2.0 is fully backwards-compatible with the current official timer APIs. Require the library in your project by adding this one line of code, preferably near the top of your a:īy taking those steps, you have updated Corona’s built-in timer library to version 2.0.Download a and place it in your project’s root directory.Updating the timer library to “timer 2.0” in your Corona project is as simple as these two steps: I still think that’s worth doing, and if you’re reading this, then you should definitely do that! However, part of what I love about Corona is how we developers can roll our own solutions to these sorts of problems while we wait for Corona Labs to add new features or fix bugs – so I decided to do just that and “fix” the timer library to enable those requested features. In my comment on that forum post, I suggested that the original poster vote up a Corona SDK feature request for the timer library to receive an update akin to the “Transition 2.0” update from a few years ago, so that we would have the ability to pause/resume/cancel all active timers at once, or to pause/resume/cancel a subset of active timers by tagging them. Under the current system, it’s very easy to accidentally leave a timer running when you would rather pause or cancel all your timers, or at least a number of them. Now the Corona SDK already gives us methods for pausing, resuming, or even canceling active timers, but those methods are somewhat restricted in that you can only cancel one timer at a time, and you must refer to the timer by it’s handle to do so. I recently commented on a post on the Corona Labs forum from a developer who was having a hard time with timers that were not canceled when a scene was changed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |