Hi guys!
I am started to use monarch for switching scenes and it worked fine until I tried to add transitions.
After adding transition url, gui is started to act kinda weird.
It stops to redirect to the correct scene and gui is not removed as expected.
To switch scenes I use proxy collection with monarch.show(hash(“start”))
Code of transition is very simple:
function on_message(self, message_id, message, sender)
print("GUI transition - message_id: " .. message_id)
pprint(message)
if message_id == hash("transition_show_in") then
msg.post(sender, monarch.TRANSITION.DONE)
end
end
Cannot find where is the problem, can somebody advice something?
Hi. So the transition isn’t actually doing anything? I’m guessing that since it is instantaneous that this messes with monarch. You can try to add a timer before sending the transition done message just to verify.
Ok, so I took a look at your project. Some comments:
You have two screens, level1 and start.
Both screens use the same transition url /gui#transitions
The transition logic at /gui#transitions defines a transition for show_out and show_in
When you click you alternate between showing level1 and start
The problem is that when you show one screen it triggers the show_in transition and at the same time you hide the other screen which triggers the show_out transition. This means that the transition logic in /gui#transitions gets invoked twice and at the same time. Only one of these will finish.
The solution is to have the transition handler set up per screen. Meaning that level1 has one transition url and start has another. This way they won’t conflict like they do today.
You could create a transition instance per screen at runtime:
local transitions = require "monarch.transitions.gui"
local monarch = require "monarch.monarch"
local function get_transition(self, screen)
if not self.transitions[screen] then
self.transitions[screen] = transitions.create(some_node)
.show_in(transitions.fade_in, gui.EASING_OUTQUAD, 0.6, 0)
.show_out(transitions.fade_out, gui.EASING_INQUAD, 0.6, 0)
end
return self.transitions[screen]
end
function init(self)
self.transitions = {}
end
function on_message(self, message_id, message, sender)
if message_id == monarch.TRANSITION.SHOW_IN or message_id == monarch.TRANSITION.SHOW_OUT then
local transition = get_transition(self, message.screen)
transition.handle(message_id, message, sender)
end
end
I would need to know more about the problem. Can you please create a ticket and also share a repro case so that I can test and see if it’s possible to create a fix: