Layer/Object stretch to fit screen

Ah so now i do ScreenWidth()xScreenHeight() to the window size and increase background size correct?

the empty spaces will be filled with black bars, when the given game size isn’t correct.

1 Like

your game background must be greater than the maximal possible game window size. and it need to be positioned correctly.

going to make it into apk and see. when i check in preview it only stretches one way

is there a way to center whatever is not the background

your scene’s origin is always the top left corner. you should reposition your camera when resolution changed. but this way only the camera moving, the position of the objects does not change relative to one another.

I tried this with center the camera on the main object. but no success

I don’t understand, what is the problem?

When i do exaclty what you said my content stays on left top as you said. So how do i make it that my “main content” always stays in the middle. I tried camera x = ScreenWidth()/2 but doesn’t work

the origin is always is the top left corner of your scene. X=0 and Y=0. this is isn’t change, no matter how many times change the resolution back and forth. the good side of this method is your objects coordinates in your scene isn’t change. so you can simply give the coordinates where want to the camera’s center be. no need math, or any expression. just put the coords.

yes but it needs to be dynamic based on any screensize that is why i was using math. the whole point is that there is no fixed size

You can search “aspect ratio” on this forum, lot of users have asked this in the past.

that is what I have explained so far. your camera and/or game resolution can be dynamic, the coordinates in your scene aren’t changed. thats why you aren’t need math in this case. just resize the camera and do its center let the same point than before. because otherwise it will snap to the top left corner. thus the play area will grow os shrink around your player. and if you set the resize parameters correctly, the screen won’t be stretch.

This is how i should do it? (scene size is 720x1280)

because it stays on top left side
(my game is completely finished its the only thing i still need to solve)

17

1 Like

yes, this is what I tought. I’m not sure how smartphone works, but I think you should be in fullscreen mode for this code. and dont forget to choose “YES” when you change the window size.