#How to correctly configure aspect ratios?

14 messages · Page 1 of 1 (latest)

verbal cairn
#

I'm making a pixel art game. I want to define a fixed resolution and ask Bevy to stretch the viewport to fit my window without changing the aspect ratio nor showing more or less of the contents.

For example, if my tiles are 32X32 tiles, and I define my resolution to be 128X64, I'm showing 4X2 tiles, and I want it to show the same 4X2 tiles no matter how I resize the window.

In Godot, there's a documentation about this (https://docs.godotengine.org/en/stable/tutorials/rendering/multiple_resolutions.html#stretch-mode). Essentially, I'd like to create the bevy equivalent of "viewport" stretch mode with the "stretch aspect = keep".

#

I tried setting the scaling_mode of the camera to ScalingMode::AutoMin and defining my resolution in the WindowPlugin, but I don't think that's it

vernal bloom
# verbal cairn I tried setting the `scaling_mode` of the camera to `ScalingMode::AutoMin` and d...

There is no way that bevy can adapt to multiple resolutions (which it must) while keeping the same aspect ratio (not warping the image) and not showing more nor less of the contents. That’s too many constraints.

If you’d like it to just not respond to the window at all that’s doable. In response though the contents of the window will be warped as the aspect ratio of the view and the window are different.

If you’d like it to respond to resizing and always have items in the render world take up the same number of pixels on the monitor, that’s also doable. In response though the view will change to accommodate more or less of the contents as the window size changes.

#

If the former, use ScalingMode::Fixed. If the latter, use ScalingMode::WindowSize. The others are variants of these.

It’s worth noting that there are other things you could do, like adding a black border around the camera to handle over-show, but this is all you can do with the built in hardware.

#

I forgot to watch your video. You might be able to do that with AutoMax

verbal cairn
#

Sorry, maybe the original post was badly worded

#

I just need it to do what the video shows

vernal bloom
#

I actually don't know what AutoMax looks like; my hunch is that it fills the extra space with the clear color. You could probably use AutoMax and modify its dimensions with correct size calculated from the window resolution every frame

verbal cairn
vernal bloom
#

Set the scaling mode to AutoMax, and then set up a system to change the dimensions inside automax to be the largest size that should be allowed, and change the camera scale to match. So if you want to always show 10x20 world units and your window is 100x300, set the AutoMax dimensions to be 100x200 (the largest size with the correct aspect ratio) and then set the camera scale to be 10 or 0.1, I can't remember which direction it is.

#

Basically you can restrict the size with AutoMax and then make sure that you have the correct amount of content with the camera scale

#

the part about the window scale assumes you're using orthographic; if you're using perspective, all of this is out the window

#

actually you probably need to use FixedVertical and FixedHorizontal to constrict the dimension that's larger than it should be