Multiple Stages on Same screen with different viewport LIBGDX - camera

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.

Related

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

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)

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?

How to prevent image float when resizing bootstrap layout

We have a typical bootstrap SPA that we turned into a React site.
In one of the sections there's an image that appears in the right side of the layout, and it spans the section vertically (takes up about 50% horizontally).
When the window is reduced in size, at some intermediary positions, the image no longer spans the section vertically, making it float above what looks like a margin or a frame, but in fact, it's just the background color of the section whose aspect ratio is not enough to hold the image completely.
Is there a way to prevent this? It seems like the only solution would be to pick images that are have aspect ratios that are more amenable to the half the grid position they are being given.

Appcelerator Studio - Don't stretch Image

I have a 405x720 image that it is to cover the background image. I've noticed that it stretches the image if the device's screen is smaller than the image. (I'm using a Galaxy S4 to test my apps).
Here's what I have so far:
var fullView = Ti.UI.createImageView({
layout: 'vertical',
width: '100%',
height: '100%',
image: '/images/background.png'
});
I've heard about the clipping technique, however that is only available for iOS and I'd like to have it for both platforms. Is there a way to do this? Or should I try to resize it appropriately? Tips/Suggestions are appreciated!
You should use proper images according to the aspect ratio of screen you are going to run your app on.
You can do this by calculating the width-height ratio of device and then you can decide which image to show on.
But putting a single resolution image directly to cover up the whole screen
is never going to work.
To resize an image, you can use Ti.Blob class' methods after fetching your image using Ti.Filesystem
Also remember that putting an image on whole background takes lot of memory especially in Android. That's why most of the apps do not use complete image to cover up background, rather they use small images wherever necessary and fills up other areas by colors or gradients as required.
But if your requirement is only to use image in background then unload it as soon as you move to different screen and load it again as you are back on it.
Further points to keep note of:
If you set bg image on a View, then it will be fit to cover the dimension of a View. So, if you have a view of width/height to 100%, then image will be fit into it. It means that image size will depend on View's dimension, not the View dimension will depend on image size.
If you set image on ImageView, and suppose you have:
ImageView width = FILL to screen size of 720, then the image height will be automatically decided to keep the aspect ratio. It means that if you have an image of size width=720 and height=400, then the ImageView will be of width=FILL & height=400
Image of size width=1000 and height=800 & ImageView height = 400, then the ImageView will be of width=500 & height=400
The problem is that you're actually telling the image control to load the image on an object that is stretched to the entire width and height of the screen - and when the screen aspect ratio is different than the one you have cropped your image by then you get bad aspect ratio and image looks screwed up.
If you remove either the width or the height, than the aspect ratio of the image will be loaded.
When I want a background image what I found the best way is to make a square image, and then set my ImageView height to Ti.UI.FILL and my width to Ti.UI.SIZE - That way it shows good aspect ratio and side that dont "fit" the screen (width or height) are not shown.

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.