Defold 1.2.86 has been released

Defold 1.2.86

This release is smaller than usual because most of the team has been away on summer vacation.

This time, we have fixed the sound performance issue on Android that was introduced in version 1.2.84.
The audio performance is now back to normal.

We also fixed an issue with the way we handled certain messages, which could lead to crashes.

And, we’ve added a new lua module called “window”. For instance, it lets the user set an event listener.
The currently supported events are window.WINDOW_EVENT_FOCUS_LOST, window.WINDOW_EVENT_FOCUS_GAINED and window.WINDOW_EVENT_RESIZED.

The window module also allows you to control the dim mode of the screen via window.set_dim_mode/window.get_dim_mode.

The game.project editor now expose the max number of Spine instances.

We’ve updated the SSDP handling in the editor, it should now be easier to find and connect to your target devices.

Engine

DEF-1146 - Added: New “window” lua module, with event listener
DEF-1260 - Added: Ability to block device from going to sleepmode
DEF-2007 - Added: Spine max count exposed in game.project editor
DEF-1999 - Fixed: Sound performance bug on Android
DEF-2006 - Fixed: Improved our device detection (SSDP) handling
DEF-2011 - Fixed: Unaligned memory (simd) in message passing

Documentation

DEF-2027 - Clarified condition for vectors in vmath.quat_from_to

11 Likes
window.WINDOW_EVENT_FOCUS_LOST
window.WINDOW_EVENT_FOCUS_GAINED

Useful!

I imagine the window module will be later extended for like

window.set_window_mode
window.set_fullscreen_mode
window.set_fullscreen_mode_borderless
window.get_display_mode
window.set_resolution
window.get_resolution
window.show_mouse
window.hide_mouse
window.set_cursor_icon
window.capture_mouse
window.release_mouse

Most of these are already functions of GLFW. A rawer access to GLFW functionality would mean anyone could implement them though.

Some constants to compare to with window.get_dim_mode

window.DIMMING_ON
window.DIMMING_OFF
window.DIMMING_UNKNOWN

if window.get_dim_mode == window.DIMMING_ON then 
...

Setting the dim mode is done in the same way. You set based on the constant. Just remember that dimming is super important to do for conserving battery life.

There is also window.set_listener. It works like the IAC listener (just tested)

local function window_listener(self, event, data) -- edited to fix mistake
     if event == window.WINDOW_EVENT_FOCUS_GAINED then
         print("focus has been gained")
     end
     if event == window.WINDOW_EVENT_RESIZED then -- edited to add example
         print(data.height, data.width)
     end
end

function init(self) -- edited to move after
    window.set_listener(window_listener)
end

We can now automatically pause games when they lose focus!

5 Likes

Yes, we wanted a good module to hold such functionality.

Minor thing, the listener has the format:

function window_listener(self, event, data)
    print(event)
    pprint(data)
end

This is because you will get the width/height in the data table, when you receive a window.WINDOW_EVENT_RESIZED

2 Likes

window.WINDOW_EVENT_RESIZED event is triggered twice when window is minimized (on Windows) and then clicked on again to show the window (both happen when clicking on the window to make it appear again from being minimized), returns width / height of 0/0 first and then second the actual width and height.

You should change the order of the init() and window_listener() functions (and make window_listener local) in your example. As the code stands now it will not work.

2 Likes