+1 vote

Hi!

I'm involved with the Escoria adventure game framework, trying to get some features that make for modern games, and am struggling with zooming.

The use-cases include talking to NPCs so that the camera closes in on the conversation and having the player move to a part of the screen and the camera pushes in.

Thus far my best results have been calculating the game ratio and using

func set_zoom_height(zoom_height):
  var game_size_ratio = game_size.x / game_size.y
  zoom_viewport = Vector2(zoom_height * game_size_ratio, zoom_height)
  viewport.set_size_override(true, zoom_viewport)

However, when I pass in a completely other zoom_height, the other things in the screen, like tooltips or the right-mouse-button menu, are also zoomed in!

I have not been able to find an approach to fixing this, so does anyone here have leads for me?

I have tried using a different viewport than /root (and a separate Camera2D as its child), but apparently it doesn't matter - anything rendered in the viewport always gets scaled. Is this a correct understanding?

Also I dabbled in calling .set_size() on child elements, but this does not seem to scale them at all, as if the call has no effect! Should it?

This solution would probably perform very badly, because the engine would constantly have to check if the scaling has already been applied. Am I right?

Is it possible to have two different viewports overlap, only one of which gets scaled?

Would there be a completely different approach I haven't tried yet?

Thanks!

in Engine by (24 points)

Interesting question! I worked with Camera2D plus extra CanvasLayers for GUI so I never encountered such a problem. But when talking about tooltips and the right-mouse-button menu I can understand your problem. As far as I know there is no specific option for this purpose in the Camera or Viewport classes. If you don't receive any working answer here you should create an issue in the github repo (and maybe don't mention that you are working with escoria framework because it could seem to be an escoria related question - which it is not). Would be nice if you could keep us updated here.

Hi!

Thanks for the reply and sorry for taking so long to get back to this.

All my theories of viewports were wrong and the correct implementation is about layering the HUD into a separate CanvasLayer.

There is a related problem, although some code was merged here

https://github.com/godotengine/escoria/commit/895a5337a2586b21057d74c05bf6fece9ab7032b#diff-7ba6a4f70a1502b64a4c21c0091edb60L164

When scaling the scene, the camera appears to be off.

You can see, a couple of lines up at https://github.com/godotengine/escoria/commit/895a5337a2586b21057d74c05bf6fece9ab7032b#diff-7ba6a4f70a1502b64a4c21c0091edb60L158 that a transform is applied to the canvas.

The purpose of this is to "clamp" the camera to stay within its given parameters, and there is a PR to make the code a bit clearer and more modern.

Anyway, the camera does not remain on its given target position, eg. the player character's position, but "zooms in" somewhere beside it. I believe the arithmetic requires something extra, but I do not understand what it might be. Trying to multiply or divide by the scale leads to some results, but never the correct ones.

Do you have any ideas or experience in this?

Thanks!

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.