Monarch - Simple screen manager

I like it! Thanks!

2 Likes

Hold my beer

37

6 Likes

Clipboard fixed, thanks for the great suggestion!

2 Likes

Hi @britzl,
First of all, thanks for making this extension. It looks pretty easy to use but I have a quick question about structuring my game.

So I have a bunch of pages. (game, home, inventory, shop, etc.) Should I have one collection for each page and then have a game object with collection proxy and screen.script inside each collection? Or do I have one collection and a bunch of game objects for each page inside? (which seems to be what you have in the picture of your file structure on the assets page for Monarch) If I do that won’t game objects from all screens be shown at once?

Would you mind showing me the ideal way of structuring pages in Defold w. Monarch?
Thanks in advance.

1 Like

Tweetfighter is a good example of how to use Monarch. Tweetfighter has a bootstrap collection containing all of the screens, like this:

So it’s one game object per screen. Each game object contains a collection proxy pointing to a collection containing the screen and an instance of the screen.script (from Monarch).

The controller.script is the one launching the first Monarch screen:

And then navigation to more screens happen based on user input within the screens themselves:

PS The example project in the Monarch should show how to use Monarch and the different API functions.

8 Likes

Thanks @britzl! This is working really well. :slight_smile: Monarch is really easy to work with! However, I do have a bit of a problem when I have a camera on one page (I’m using ross.grams’s wonderful Rendercam library) I’ve posted a question on the forum. Not sure if you’ve seen it yet. Here’s the question
Thanks again.

2 Likes

It looks like you ran into a limitation of Rendercam that I haven’t gotten around to fixing yet, not a problem with Monarch. I answered in the other thread.

3 Likes

Let’s say you have:

Screen A,
and you open up:
Screen B (popup)

What would be an easy way to make sure input is not registered on Screen A while Screen B is open?
I want to keep Screen A visible ‘behind’ the popup but not allow interaction.

Monarch is designed so that it is only ever the screen at the top of the stack that has input focus. And to create popups all you need to do is check the Popup checkbox of the screen.script. Popups work in the exact same way as other screens in terms of inout handling. The only difference is that the screen below it will not be unloaded.

1 Like

Right you are, I got confused over this due to another issue.

I create screens the same way as in the example project of the extension. Works great.

I have one specific screen, the upgrade shop. From this screen, I want to popup certain info boxes etc. This also works, by adding these screens to my main collection with monarch scripts etc.

However I tried something I felt was intuitive at first, but it didn’t work:

I added these popups, but instead of putting them in the main collection, I put their respective game objects and collection proxies in my Shop collection. The idea being that these only ever show up while having the Shop screen under them, so let’s isolate them there.

It worked fine to make these popup screens appear, but for some reason I never could get input to register on them.

Am I breaking convention here or should it work? If it should, I should probably try it more thoroughly.

This is probably the reason it’s not working. Remember that for anything inside a collection proxy to get input it is required that the game object containing the collection proxy has input. And the input on the game object containing the Upgrade Shop will release input focus when one of the input boxes are shown. This means that the required chain of game objects with acquired input focus breaks and anything inside the upgrade shop proxy will not get input focus.

I’m not sure how to make your setup work properly with Monarch. The short term solution is to not nest screens like that.

Ok cool.
The game is small enough for this not to be a mess in the editor so I can keep it all in the main collection, and solve it in a more intricate way when I start making triple-A games :grimacing:

2 Likes

Hi, I was wondering, if it is possible to easily make fade-in and out transitions between screens with Monarch? As far, as I understand custom_transitions allows us to make custom target position. But what about adding option to animate to target color?

Custom transitions can do anything you want. The only requirement is that you send a transition_done message when finished (in your case fading in/out).

2 Likes

You can use code like in top comment here to create a gui node that you can then animate how you want while you transition

2 Likes

Updated URLs (the top one doesn’t work):


2 Likes

Hi. I saw that this link https://www.defold.com/community/projects/88415/ was broken. If it is possible, can you update link to real project?

Sure thing, here you go: https://defold.com/assets/monarch/

2 Likes

@britzl, Thank you very much.

Hey @britzl, thank you so much for this amazing extension! Pretty sure I’ll use it in all my projects (once I’ll finally make it work).

But for now… I just added Monarch to one of my prototype and set it up just like in the Tweet Fighter example (pretty cool game name by the way :grin:). Only changed a bunch of URLs/paths and names/ids…

But for some reason… it doesn’t work. I thought I got how it worked and it seemed really easy to use, but I must have missed something important and I don’t know what. Maybe you can help :pray:

Here are a few screenshots of the set up:

image
image
image
image


Here is my controller.script (supposed to automatically load the char_selector collection):

local monarch = require "lua-modules.libs-defold.monarch.monarch"

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#", "start")

	self.test = 0
end

function update(self, dt)

end

function on_message(self, message_id, message, sender)
	if message_id == hash("start") then
		monarch.show(hash("char_selector"))
		self.test = self.test + 1
		print("self.test = "..self.test)
	end
end

Result: black screen

and the debug “self.test” variable is endlessly set to 1.
image

No error message, but nothing happens. :thinking::sob:

Is my controller script looping on itself or something? (since the self.test is not incremented beyond 1)
(I really don’t see any differences between my “char_selector” screen and the “title’” screen of the Tweet Fighter project)


PS: probably nothing to do with my issue, but:
image

PPS (edit): nothing to do with my issue, but… in this situation (issue/question related to some old stuff), should I bump the old topic or create a new one? :thinking: