Problem using Monarch with RenderCam (Using collection proxies with a camera)

Monarch will acquire input focus from the screen.script assigned to the screen that is currently at the top of the stack: https://github.com/britzl/monarch#input-focus and the code: https://github.com/britzl/monarch/blob/master/monarch/monarch.lua#L215

At least that’s the idea… It should work.

Well, I don’t think it worked for me without acquiring input focus in screen.script which is a component of all the game objects (corresponding to each screen in the game) in main.collection.
Did it work on the project I sent you?

Is final() supposed to get called when Monarch switches between screens? With whatever I’m doing, I’m able to detect input in game.collection when it’s open and also from another collection I have called end.collection after I open it with Monarch. Is this how Monarch is supposed to works?

final() is called on a script component when the game object the script is attached to is removed. The whole process of input is supposed to work like this:

The above screenshot is of the bootstrap collection of the example that comes with Monarch. The main.script does:

monarch.show(hash("menu"))

When this happens Monarch will start the process of showing the menu screen. The first thing that happens is that Monarch will acquire input focus for the menu game object and then it will load the menu.collection containing the screen itself. Acquiring input focus for the game object containing the collection proxy is handled by Monarch and it is something that must happen if you want any input from the user to propagate to any scripts within the menu.collection. This is described in the section on Input and Collection Proxies in the Defold manual on input. Note that you still have to acquire_input_focus in any script inside the menu.collection yourself.

What this means is that Monarch will make sure that input can propagate down to any script attached to a game object in the topmost screen of the Monarch input stack. Monarch will acquire input focus for the topmost screen and automatically release input focus from any other screen. BUT you still have to take care of acquiring input focus within the screen itself.

1 Like

I’m really feel like I’m doing exactly what you’re saying, but now it doesn’t seem to be working. The only place where I am acquiring input focus is in game.gui_script where I get input from my 2 virtual joysticks. (They are GUI nodes) What you’re saying makes sense to me, but it just isn’t working. :frowning_face: It only works when I add message passes to acquire input in Monarch’s screen.script and game.script which is attached to a go called game.go in game.collection.

I did send you my project by email. If you get a chance, I would really appreciate it if you could try to get it to work. I’m really, really confused.

Looking in to it now.

1 Like

Ok, so here’s what’s going on. When a screen is shown a series of things happen:

  1. The screen is unloaded if the reload flag is set
  2. The screen is loaded if it’s not already loaded
  3. The screen transition is played (instantly shown if no TransitionUrl is provided)
  4. Input is acquired
  5. A focus gained message is posted to the screen if a FocusUrl is provided
  6. DONE!

This sequence can be seen here:

The steps described above all happen in sequence, one after the other. If one step fails the next will not happen. In your case you specify a Transition Url for your game screen (game:/game#game) but in the game.script you do not handle the transition message and send a monarch.TRANSITION.DONE when the game screen transition is completed. And since you don’t send a monarch.TRANSITION.DONE message the next step in the sequence will not happen (which is acquiring of input).

The solution is to either handle the screen transition or remove the Transition Url.

It may seem like a stupid thing to wait for the screen transition to complete but I think in certain cases it makes sense to actually wait to acquire input until the transition is finished. And it’s better to have it that way and if you don’t want to wait for the transition to finish you can handle that yourself in your transition code by sending monarch.TRANSITION.DONE while the transition is running.

Make a short video explaining it with a simple flash animation. For some reason I get the urge to do tutorials on Defold(Basics) but then I get lazy and rather sleep

2 Likes

Thanks, @britzl! It’s working perfectly now! :slight_smile: Monarch is definitely easier to use than I thought. :smile:

1 Like