Monarch - Simple screen manager

I’ve had this screen manager library on my GitHub account for a while without sharing it. I was reluctant to share it since there already exists a couple of Defold screen managers and I didn’t feel Monarch was battle tested enough to go public with it. I have since then used it in a couple of projects and received some community feedback and pull requests and I feel that now is the time to announce it here. So here we go:

Monarch is a Defold screen manager with transition support and a straight forward API

Monarch screens are created in individual collections and loaded through collection proxies. The recommended setup is to create one game object per screen and per game object attach a collection proxy component and an instance of the screen.script provided by Monarch. The screen.script will take care of the setup of the screen.

The navigation in Monarch is based around a stack of screens. When a screen is shown it is pushed to the top of the stack. When going back to a previous screen the topmost screen on the stack is removed.

You show a screen by calling monarch.show(screen_id). You navigate back to a previous screen by calling monarch.back().

Monarch supports both normal screens and popups. It also supports a simple screen transitions system.

Learn more here: https://defold.com/assets/monarch/

18 Likes

Could I make the logo/ thumbnail for this if no one else will soon?

Monarch is great! I’ve been using it in several examples and commercial projects.

4 Likes

My favorite Defold screen manager!
I use in several my projects!

3 Likes

@Axel is doing one but why don’t you go ahead and create one as well and then we’ll put it to a vote? :slight_smile:

I’m dropping this—@pkeod, go crazy! Great initiative :raised_hands:

1 Like

monarch_mini

Something like this?

Imp and Clipboard are still missing icons too… Imp could have a cute demon mascot, clipboard could have Clippy…

Attached zip

monarch_images.zip (493.7 KB)

5 Likes

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