GML When resolution is not in fullscreen and you swap resolutions, the game is not centered on the screen - gml

I have settings screen within my game for resolution. Within this setting page, you have a fullscreen ON and OFF option. I also have a resolution switcher above it. However when you turn fullscreen off and change the resolution. The game is no longer centered on the screen and moves around as you change the resolution. I have tried many things such as window_center() within the switch statement. However this isnt solving my issue. Does anyone have any ideas on how to keep the game centered on the screen when changing resolutions with fullscreen turned off? (Such as a windowed fullscreen)

You'll want to either delay window_center call by 1 frame (as the window position data doesn't update till the end of the frame), or use window_set_rectangle to calculate position yourself immediately, like so
window_set_rectangle((display_get_width() - width) div 2, (display_get_height() - height) div 2, width, height);
(or slightly more complex if you want to resize window relative to the current position)

Related

Make text stick to top of screen, even when moving camera

I am learning Haxe Flixel. I have a text that I want to stick to the top of the screen. I couldn't find anything in the API. How can I make a textObject stick even when camera centered around player is moving?
Similarly. How can I set up lower bounds of the screen, to make camera not have the radius around my player, and have the lower bound at the bottom of the screen?
Use scrollFactor
object.scrollFactor.set(0, 0);
https://snippets.haxeflixel.com/camera/scrollfactor/

Unity Prevent game objects from resizing when resolution changes

I have a rectangle sprite that animates when a score is reached. Starts offscreen and then move onscreen before moving off-screen again. Works fine. Problem is when I change the resolution for different devices the sprite resizes and doesn't display as intended. The text fields inside the rectangle move outside on some of the resolutions. How can i keep the sprite at the original size regardless of resolution. I have tried Preserve Aspect, Set Native Size, moving anchors but it still resizes. I also tried using a panel.Any Ideas?

Multiple Stages on Same screen with different viewport LIBGDX

I am trying to scale my application to work similar on various aspect ratios.
I read about viewport and camera. And came to a conclusion that I should use FitViewport for my game stage so that no asset is being stretched. And I will use some background image to fill the black bars caused by fitviewport. But the problem is, whenever I use any other viewport than FitViewport for background image, the whole stage (both background and main stage) are being stretched, is there a way we can get away from black/white bar of FitViewport? I tried all the viewports for background namely StretchViewport, ScreenViewport, FillViewport.
Am I missing something very trivial? or is setting up multiple different viewport on same screen possible.
ps I was able to setup two same viewports with different size on same screen.
Here is the screen, I am getting after fitviewport. Notice the white bars on top and bottom which I am trying to eliminate.
this answer worked for me. Just for reference
You would need a second viewport, probably ExtendViewport with the
same virtual dimensions as your FitViewport.
//create:
fitViewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
extendViewport = new ExtendViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
//resize:
fitViewport.update(width, height);
extendViewport.update(width, height);
//render:
fitViewport.apply();
batch.setProjectionMatrix(fitViewport.getCamera().combined);
batch.begin();
//draw game
batch.end();
extendViewport.apply();
batch.setProjectionMatrix(extendViewport.getCamera().combined);
batch.begin();
//draw stuff in border
batch.end();
If you want to be sure the border stuff doesn't overlap your game, you
could swap the draw order above.
Or you could just use ExtendViewport to begin with for everything.

How to build a Head Up Display in OpenSceneGraph that resizes depending on the screen's resolution?

I'm pretty new to OpenSceneGraph and I have the following problem:
I'm trying to build a 2D Head Up Display out of several images, so that it can resize depending on the screen's resolution. That means I have extra images for the corners and one image for the bar that connects the corners and so on.
Well, that's the idea. But I have no clue how to do that in OpenSceneGraph.
Can anybody help me?
So, when the window resizes, you'll get an event from osgViewer telling you about the change.
You need to resize your viewport when the window size changes, so your HUD geometry has some idea of what the pixel-size of the display is (most of the HUD examples setup for a nominal 1024x768 screen and then just let that stretch around as the window is resized, pretending like the new viewport is still 1024x768).
Once you've resized the viewpoer, you need to rearrange your geometry. Your corner pieces need to be laid out at the fixed pixel size you want them to always appear, then you need your connecting elements to change size, horizontally or vertically, to fill the space between the corner pieces. You usually rely on texture stretching or repeating to fill the space as the piece of geometry gets stretched.
If none of that makes any sense, I can describe more.

UIWebview rotation+transform issues

When a user presses a button i add a scale transform to make it zoom out like safari's tabbing. when user presses the webview it comes back up. When the view is rotated, i use to get the values of how i wanted the frame to look like in tab mode, and checked if it was in tab mode when rotating and applied the frame. it works, and ive tried taking it out. The issue is, if i rotate like 10 times, a black line on the right side gets bigger and bigger going inside the webview. i have logged tons of objects for the web view and its scrollview to see if anything is off, the scrollinset/offset is correct, the frame is correct, the transform is correct too. i cant figure out why theres the black line. i tried refreshing the webview to see if its the webpage, and it doesnt fix that ether,the scale transform values is
CGAffineTransformMakeScale(0.6, 0.68)
for zoom out, and 1, 1 for zoom in. if anyone wants to see the effect just apply that to a uiwebview and start rotating the device about 10 times and you would then really see it.
heres how the web view looks when rotating a bunch of times:
on the right side theres that thick black line, it gets bigger with every rotate but ONLY grows when that transform is added, if its normal size again it stops but stays there.
When you transform any view, their frames do change, If you are using autoresize flag, check it since transforming changes frames and autoresizing also changes frames and this creates weird result.