This release adds Lua module timer to scripts. This allows you to set a delay and a callback to be called when the timer completes. We also added functions sprite.play_flipbook, sound.play, sound.stop and sound.set_gain besides posting messages for these functions.
Engine
DEF-1183 - Added: Timer API, timer.delay and timer.cancel.
DEF-3315 - Added: New sprite and sound message wrappers.
DEF-3313 - Fixed: Facebook Gameroom is now dynamically loaded by our extension.
DEF-3311 - Fixed: Updated OpenAL to latest built version for Win32.
Editor
On the editor side, we’ve added the ability to edit game-specific text files using the code editor. JSON files support syntax highlighting, but you can edit any text file. We’ve also added the ability to toggle between local- and world-space manipulators in the Scene View.
DEFEDIT-887 - Added: Scene view manipulators can be toggled between local- and world-space.
DEFEDIT-1235 - Added: Non-spine JSON files can now be edited using the code editor.
DEFEDIT-1319 - Added: Unrecognized text files can now be edited using the code editor.
DEFEDIT-1407 - Fixed: Sometimes the NE build cache was invalidated between editor sessions.
Docs
Added new RPG map sample. It’s available from the editor welcome screen (New Project -> From Sample) and on Github: https://github.com/defold/sample-rpgmap.
We forgot to add the new namespace timer.* to the docs. This will be fixed today. Until that happens here’s the docs for timer.create() and timer.cancel():
/*# Create a timer
* Adds a timer and returns a unique handle
*
* You may create more timers from inside a timer callback.
*
* Using a delay of 0 will result in a timer that triggers at the next frame just before
* script update functions.
*
* If you want a timer that triggers on each frame, set delay to 0.0f and repeat to true.
*
* Timers created within a script will automatically die when the script is deleted.
*
* @name timer.delay
* @param delay time interval in seconds
* @param repeat true = repeat timer until cancel, false = one-shot timer
* @param callback [type:function(self, handle, time_elapsed)] timer callback function
*
* `self`
* : [type:object] The current object
*
* `handle`
* : [type:number] The handle of the timer
*
* `time_elapsed`
* : [type:number] The elapsed time - on first trigger it is time since timer.delay call, otherwise time since last trigger
*
* @return handle identifier for the create timer, returns timer.INVALID_TIMER_HANDLE if the timer can not be created
*/
/*# Cancel a timer
*
* You may cancel a timer from inside a timer callback.
* Cancelling a timer that is already executed or cancelled is safe.
*
* @param handle the timer handle returned by timer.delay()
* @return true if the timer was active, false if the timer is already cancelled / complete
*/
How does this timer compare to your own timer, @britzl? Is it the same (in terms of performance etc, or even the same code) or do you recommend using this new one over the previous one?
An important difference that @Mathias_Westerdahl pointed out: The timer update is inherited from the collection in the new one, meaning that it will respect the update frequency of the collection. If you pause or speed up the collection (using set_time_step) it will also affect the new timer.
The old timer (the one I wrote as an extension) is a global timer based on the system clock time. It is not in any way affected by the time step or anything like that in the engine.
local function timer_callback(self, handle, time_elapsed)
print('handle: '..handle)
print('time_elapsed: '..time_elapsed)
end
local timer_id = timer.delay(2, false, timer_callback)
timer.cancel(timer_id)
Results in the following console output after 2 seconds:
Is the callback called even if a timer is cancelled?
Also, in the absence of pause/resume it would be really nice to have the same callback function(self, handle, time_elapsed) with timer.cancel() as with timer.delay(). It would then be possible to cancel (pause) an existing timer and resume (create a new one) based on how much time was left.
It appears the new timer functionality isn’t happy about having britzl’s native timer module included in the project. I’d been using this previously and hadn’t removed it.