#Show more or less of the pixel art game when resizing window

1 messages · Page 1 of 1 (latest)

harsh verge
#

Hi there !
I'm currently working on a pixel art game. I have my window stretch to:
Mode : Viewport
Aspect: Expand
Scale: 1.0
Scale mode: integer

These parameters introduce black bands when resizing my window both in width and height at the same time.
I would like to replace these black bands just by showing more of my game. Is there any built-in way to achieve that without creating a new viewport ?

It is possible to get the Transform2D responsible of the black bands with get_screen_transform(), but I didn't find a way to modify it properly.

You can see the black bands in question in the following screen.

Thanks in advance for your answers !

sonic ruin
#

If you want perfect integer scaling, then you can't really do this. But you can just turn that off, and then it will expand properly

harsh verge
#

Yeah, the idea is to keep an integer scaling. In the theory it sounds pretty simple tho, scale the base resolution by an integer and expand how much game is shown to fill the current window size. I'm quite surprised that there is no build in way to do that

light thunder
#

I think what you'd want to do is very near the root of your scene use a subviewport with a fixed size larger than the screen, so that the pixels drawn to the screen are a sub-rectangle from that bigger viewport

#

and manage the size of that viewport in math, using some combination of hardcoded design constraints and the user's actual window size

harsh verge
#
var scale_x: int = floor(size.x / BASE_WIDTH)
var scale_y: int = floor(size.y / BASE_HEIGHT)
var scale: int = max(1.0, min(scale_x, scale_y))
content_scale_size = Vector2i(size.x, size.y) / scale

Simply using content_scale_size when the window size change seems to do what i wanted. Thanks for the feedbacks !

light thunder
#

interesting. The problem will be some stretch and skew -- your square tiles aren't really square

harsh verge
#

I forgot to mention that it is necessary to pass scale mode to fractionnal

light thunder
#

(or am I mistaken? I haven't throught through the implications of the math)

#

I thought you were trying to do "overdraw" -- render more of the game than you intend, and then slice one viewerscreen's worth out of that

#

which I think you can only do with some slightly careful viewport trickery

#

I think what you're doing is just the normal fractional scaling (?), though like I say I haven't thought through the math 🙂

harsh verge
#

Nop, that differs from the fractionnal scaling 😄 The goal is to obtain an integer scaling. In fact this solution is jsut to take the base resolution i want (in my case BASE_WIDTH = 320, BASE_HEIGHT = 180) and then to "create?" another resolution that will scale perfectly to the current window size. This other resolution that scale well is just window_size / computed_scale (the scale computed from my BASE_RESOLUTION).

#

I don't think what i wrote is really clear but in short, with this i have integers in the final Transform2D (seen with get_final_transform())

#

Well not really integer but floating numbers very close

harsh verge
light thunder
#

oh, I thought you were avoiding underdraw -- letterboxing or whatever