3
0
mirror of https://github.com/britzl/monarch.git synced 2025-09-28 18:42:21 +02:00

Improved examples. Added transitions

This commit is contained in:
Björn Ritzl
2017-09-04 21:26:06 +02:00
parent 1e4b7ea60f
commit a68fac766f
14 changed files with 416 additions and 90 deletions

View File

@@ -1,13 +1,16 @@
local monarch = require "monarch.monarch"
local transitions = require "monarch.transitions.gui"
function init(self)
msg.post(".", "acquire_input_focus")
self.play = gui.get_node("play_button")
self.back = gui.get_node("back_button")
self.play_position = gui.get_position(self.play)
self.back_position = gui.get_position(self.back)
gui.set_position(self.back, self.back_position + vmath.vector3(0, 1000, 0))
gui.set_position(self.play, self.play_position + vmath.vector3(0, 1000, 0))
self.transition = transitions.create(gui.get_node("root"))
.show_in(transitions.slide_in_right, gui.EASING_OUTQUAD, 0.6, 0)
.show_out(transitions.slide_out_left, gui.EASING_INQUAD, 0.6, 0)
.back_in(transitions.slide_in_left, gui.EASING_OUTQUAD, 0.6, 0)
.back_out(transitions.slide_out_right, gui.EASING_INQUAD, 0.6, 0)
end
function on_input(self, action_id, action)
@@ -23,15 +26,5 @@ function on_input(self, action_id, action)
end
function on_message(self, message_id, message, sender)
if message_id == hash("transition_show_in") or message_id == hash("transition_back_in") then
gui.animate(self.play, gui.PROP_POSITION, self.play_position, go.EASING_INQUAD, 0.6, 0, function()
msg.post(sender, "transition_done")
end)
gui.animate(self.back, gui.PROP_POSITION, self.back_position, go.EASING_INQUAD, 0.6)
elseif message_id == hash("transition_show_out") or message_id == hash("transition_back_out") then
gui.animate(self.play, gui.PROP_POSITION, self.play_position + vmath.vector3(0, 1000, 0), go.EASING_INQUAD, 0.6, 0, function()
msg.post(sender, "transition_done")
end)
gui.animate(self.back, gui.PROP_POSITION, self.back_position + vmath.vector3(0, 1000, 0), go.EASING_INQUAD, 0.6)
end
self.transition.handle(message_id, message, sender)
end