Cocos2d-x: how to make full screen background? - windows-store-apps

In my cocos2d-x game, my design resolution is 768x1024 (portrait), and I using "kResolutionShowAll" strategy (since I want to obey assets ratio). On some screen resolutions (e.g. Windows 8 PC 1920 x 1080), I have black borders on the sides.
I want to avoid these borders. My idea is to place some image as a background and to stretch it in order to fill the whole screen, and this way to avoid black borders (so, the scene should be rendered on top of that background).
My question is: how to do that? No matter how I trying to scale my background image, it always rendered within display resolution...
Thanks!

First thing first, find out the max resolution of the device family you are targeting. For example, if you are targeting Android family then the max resolution is >>> 2560x1600 (nexus series)
You can create your assets in this resolution then scale them according to different aspect ratios of devices (the scaling strategy, which in your case would be "kResolutionExactFit")
Btw, there is no harm in showing borders, several games do that. When we faced this issue, we applied the same strategy as I mentioned above(2560x1600 resolution images, with kResolutionShowAll strategy) Also, we set "setDesignResolutionSize" to "(1600, 2560)"
So, on 2560x1600 res. devices it fit well, but on 1920x1080/1280x720 devices there were borders. Please note that images that large can also result in a black screen when rendered, i.e, if a device is incapable of rendering an image(image greater than maxtexturesize of the device), cocos2dx won't render it.
In this case you can use,
CCConfiguration* conf = CCConfiguration::sharedConfiguration();
conf->getMaxTextureSize() // to check if a device is capable of rendering such image, if not you can use a lower resolution version
Or, you can also have 2 diff design resolutions.
Having said that, if you stick with "kResolutionShowAll", your game might look stretched. Just for reference, I have shared the definitions of different strategies;
kResolutionShowAll
According to the width and height of screen and design resolution to determine the scale factor, choose the smaller value of factor as the scale factor. This can make sure that all the design area can display on screen, but may leave some area black on screen.
kResolutionExactFit
Set the width ratio of the screen and design resolution as scale factor in X axis, set the height ratio of the screen and design resolution as scale factor in Y axis. This can make sure the design area cover the whole screen, but the picture maybe stretched.
kResolutionNoBorder
According to the width and height of screen and design resolution to determine the scale factor, choose the larger one as the scale factor. This can make sure that one axis can always fully display on screen, but another may scale out of the screen.
taken from,
http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation

Related

What is the max picture width and height in bootstrap 4 grid class col-4. commands to help reduce blury images

Hi so I wanted to put 3 screenshots on 3 columns in one row like step 1,2,3 I wanted to make them all the same size. I was wondering what's the max width, height I could put before it gets stretch or compress or something (using bootstrap grid col-4). Also is there a command that helps reduce blurry picture. My pictures are a little bigger (not too big but bigger than it's suppose to be so it gets a litte blurry. so for example 300px width 300px height
What you're asking entirely depends on the pixels of your said screenshots. The smaller the pixel dimension, the smaller width and height before it starts to get too pixelated. Generally you can optimize pictures pretty neatly for web by using either Photoshop, similar or online tools.
Back in the old days (actually not that old), people used to say 72dpi/ppi (dots/pixel per inch) would be the optimal use for web, and 300dpi/ppi would be optimal for print. It honestly doesn't matter what the dpi/ppi is for web unless you are going to optimize for retina displays, in which case you'd want a better quality image than normal. You can for instance use media queries for that to check what the pixel ratio on a certain device should be before you change your pictures to a higher pixel resolution scale.
Example:
#media
(-webkit-min-device-pixel-ratio: 1.5),
(min-resolution: 144dpi){
/* Retina-specific stuff here */
}
This example along with more information about retina displays can be found here.
Normally when you're thinking webdesign / webdevelopment, you'll have a design guide / documentation, dictating the exact dimensions for x,y,z images on a certain page / pages.
My advice would be to think more about the overall memory size of the image. You can have nicely optimized images for practically any dimension at 200kb in size. Too heavy images will affect your page performance hugely in a negative way as the loading speed will be significally longer.

Image resolution and brower-resizing

I've got a couple questions about the use of images in a html document that I couldn't find an answer for.
Why is the standard 12x12 / 24x24 / 48x48 / 96x96 /... and not 8x8 /
16x16 / 32x32 / 64x64 / ... ?
Why is a 130x130px image resized to 50x50px by the browser (by
setting its width/height in the html doc) going to be more blurry
than a 100x100 image resized to 50x50 ? (is it just easier for the
browser to divide the size by 2 ?)
Is there a specific resolution for images that is worth using over another to be
more 4k friendly ? For instance using 384x384px images instead of
96x96 for 4K screen owners ?
1. Why are there icon size standards?
First of all there are no "standard" sizes for icons but it is always a good idea to create icons with a equal ratio = square images. That does not mean you are not allowed to break the rules, but it depens for which medium you are creating the icons. Android using a differend base size then iOS, because they need to support different resolutions. For desktop it is always good to start from a scale of 16px as a base. reference for icon sizes
2. Why get images blurry when resizes?
Image you are the browser and you need to repaint your 120x120px pixel image into an 50x50 canvas. The problem you face right now is that you need to decides on several point which color to choose especially on edges? What the browser does ist to mix up colors for edges where he knows there is not more enoug space to display it crisp. This is causing the "blurry" effect. No think about resizing the 120x120 to the half. Thats a lot more easier because you dont need to mix colors anymore. Or in more technical term:
Well rastered images when scaled in either direction are going to have some anomalies. When you make them bigger, it’s obvious – things get pixelated quickly. When you shrink them down, whatever is rendering it has to guess on what pixel goes where. https://css-tricks.com/forums/topic/scaling-down-images-with-css-makes-them-blurry/#post-188194
3. Are there a specific resolution for images
Thats basicly a very good question and opens the topic of "responsive" Images. As you know the pixen density on 4k Monitors / Smartphones is a lot higher then on regular screen. The fact that images cannot scale the informations by themself makes them pixelated when enlarged and blurry when shrinked. Best case would be to use SVG as often as you can, icons are best usecase for icons. Normally just putting the bigges image online would do the task, but performancewise it would be catastrophical. If you want to master this topic I can give you some good links to dive in:
https://css-tricks.com/optimizing-large-scale-displays/
https://css-tricks.com/responsive-images-css/
Hope thats answers, at least, a bit of your worries :)

libgdx resolution/density scaling assets

Quick question,
I am working on a game in libgdx and have hit a snag. I'm trying to scale my assets and I'm using Gdx.graphics.getDensity() to get the density and then setting my asset size using that as a multiplier. The issue I'm having is that on a tablet that has a 2560x1600 resolution has a density of 2.0, yet the nexus 5 emulator that has 1080x1920 has a density of 2.652... how does the tablet have a smaller density then the smaller phone?
What should I be using to get my multiplier for scaling if density is not reliable based on the android app screen size?
To answer your first question, it's a hardware thing. The Nexus 5 probably has a higher PPI (pixels per inch) ratio than the second, even though the resolution is smaller.
As to your second question, I would propose an alternative to Gdx.graphics.getDensity(): If you are trying to make sure that your asset is the same size relative to the screen (i.e. a 80x80 asset on a 2560x1600 display would be half the size on a 1280x800 display), then I think you want to leave your assets the same size and change the size of your camera instead.
When you create a game in libGDX (or any game engine), you need to keep in mind the difference between three sets of sizes/coordinates in your game:
Viewport size is the size of the space on your screen where your game will draw. It is measured in pixels and defaults to your window size (in a fullscreen game, the size of the screen).
game world size/coordinates are completely arbitrary. They are measured in whatever unit you want (be it meters, inches, bananas, F16s, etc.). You'll know you're working in game world units because you have floats.
camera size is the amount 'world' you can see at one time measured in game units. You can make your camera show a 1280x800 portion of the world or a 3x5 portion of the world or a 137.6x42 portion. The tricky thing is that libGDX's OrthographicCamera class defaults your viewport size, acting as though 1 game unit == 1 pixel.
Hopefully that made sense. Let's look at the implications:
Say I have a 800x600 GU (game unit) asset at 0,0 in my game world. My viewport size is 2560x1600, and my camera is scaled to 2560x1600 as well. My 800x600 GU object will render a 800x600 px image on the screen.
Now suppose I want to port my game to other screen sizes with the same ratio (just to keep things simple for now). I still have a 2560x1600 viewport size, but I change my camera to 8x5 GU and my game object to 2.5x1.875 GU. These sizes will be set explicitely- independent of the viewport size. This makes 1 GU = 320px. The net result is that my game object will still render a 800x600px image on the screen.
Now let's see how this would work on a 1280x800px resolution: My viewport is 1280x800 px, but my camera stays at 8x5 GU and my game object at 2.5x1.875 GU. Because of the size of the camera, 1 GU = 160px, which means my game object renders at 400x300, which means it is proportionally the same size on the smaller screen.
Hopefully that made sense without pictures. When you start using screens with different aspect ratios (i.e. you go from an 8x5 screen to a 3x2 screen), you need a little extra logic to keep the aspect ratio of your viewport the same as your camera (otherwise things get all stretched). Fortunately, libGDX provides some viewports which will do this for you.
You can find an external tutorial by the libGDX community here that talks more about this issue.

Screen Resolution and Image Size, how to be correct [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Not very keen on how resolution and image sizes work.
Say I have a screen with resolution 1920x1080 pixels. Does that mean any image that I have smaller than that will lose quality if I stretch it to fit that size?
In other words, if I have an image view in an app or a box on a website or something that's 500x500px, any image smaller than that will lose quality if I stretch it to fit that, but anything 500x500px and above won't lose any quality?
I just see a bunch of different resolutions, pixels per inch, etc, so I'm not sure what to make of all of it. Thank you.
That is an interestingly put question with slightly difficult answers. Since this has nothing to do with any specific OS I will answer in a general sense.
Stretching an image (assuming you keep aspect ratio) does not reduce the quality of that image, but it will look visually inferior than an image with the native resolution of your stretched image. Stretching an image does not decrease the amount of data stored in the image, therefore there is no loss of quality. If you take a 1px by 1px image and stretch it to 1000 by 1000 it will have the exact same detail as it did at it's native resolution of 1 by 1. It may look crappy, but you did not lose any quality from the original.
Decreasing the physical size of the image does lose quality, but does not look graphically worse like stretching does. When you scale an image down the display (graphics hardware) needs to cut out pixels and average them so that it can display that image on the screen. This doesn't effect the visual quality as much as stretching, but it does effect the absolute quality of the image.
So with all of that said, I'm guessing you are worried about visual quality, not image quality. Pixels per inch has no bearing in this discussion, as that's just a definition of the screen size and resolution. Your image will appear identical on a 1ppi screen as a 1000ppi screen, it will just be 1000 times bigger physically.
To get the best visual quality it is a bad idea to scale up since there is limited image quality to fill the extra space, so you lose visual quality immediately upon scaling up. Scaling down is better because you don't lose visual quality. A 50x50px image scaled down to 1x1px will look identical to a 1x1px native image, but the opposite is not true.
When scaling down, with regards to iOS devices, you also get the benefit of the device graphical hardware giving you more pixels per image point size. If you take a 500px by 500px image and display it on a retina device in a 250point by 250point screen space rectangle you will display on screen the full 500px by 500px quality of the image. On a non-retina iDevice you will get a scaled down (by half) version of that image displayed on screen.
So in answer to your question. The way to get the best visual quality of your graphics is to make the graphic the exact pixel dimension you want to display it. Then you are not scaling up and losing visual quality and you are not scaling down losing image quality. Sometimes this requires making multiple sets of a single image in different resolutions for different screen hardware. That is the cost of getting the best quality. You need to find the best performance/quality set for your needs.
Virtually everything you said is correct. Any reference to a physical measurement (such as inches) in reference to resolution is extraneous; a printer decides how many points make up an inch (ppi), and every differently sized screen with the same resolution will have a different number of pixels per inch.
Your question is really about raster graphics; images which are saves as a grid of pixels. If you try to express 10 pixels over a space 20 pixels wide, it has to make up 10 of those pixels (and obviously there's stretching if you add pixels across one axis and not the other). The rule of thumb is don't expand a picture by more than 10% in any direction. It's generally better to use a larger image in a more compressed format than to stretch a smaller, higher quality image (compression keeps the "number" of pixels, it just uses some sneaky math to store them more efficiently, sometimes causing its own distortion).
The one thing we haven't touched on are "vector" graphics. These images essentially "redraw" themselves in whatever size you need. So, if I draw a little circle, and I decide I need a big circle, I don't magnify the little circle (that's what digital zoom is; just magnification), I draw a new, bigger circle. Of course, all the image types we deal with on a regular basis (jpeg, png, bmp, gif, tiff, etc) are raster images.
I hope that helps!
Addendum
You may find this useful (at least the part on rasters). Remember: dpi is just the resolution expressed over the area of an inch. It's like how a city's "density" is its population expressed over the area of a square mile. What matters is how many people/pixels there are, and things only get weird if you need to fill space (resolution/land) with people you don't have.
http://www.youthedesigner.com/graphic-design-tips/how-to-explain-raster-vs-vector-to-your-clients/
Are you working with iOS? you tagged this post as iOS.
If so, then in iOS you don't count pixels usually but points. And the point can be 1, 2 or 3 pixels in width and height on different devices (retina display point is 2x2 px, on iPhone 6+ it's 3x3 px).
So if you have 1920x1080 retina, you should provide image with 3840x2160 px. If you want support different types, you should use more images with different sizes.

Images pixelated in higher resolutions

I'm developing a game using libGDX framework but I have some problems trying to adapt it to different resolutions. I'll give an example of the problems I'm having.
I use Scene2D to show a simple menu. That menu have some buttons with textures loaded from a texture atlas (button textures are 9patch). In desktop, with a resolution of 800x480 the buttons look nice (even the BitmapFont) but in Android, where I use setViewport to keep the width (800px) but scale the height keeping the aspect ratio, I get pixelated images. I think that this is because my mobile higher resolution. The whole stage must be scaled to fit so the images appear pixelated.
So, my question is, what is the best way to solve this? How can I support different resolutions without end with a pixel art look?
What resolution is the android device you tested it on? You said you've used 9-patch images. This should not produce pix-elated results unless your setting them to a size and then modifying their scale(difference between screen resolution and viewport size). If you don't want any scaling you should use your screens width or height for the viewport and calculate the other one by keeping your aspect ratio. This means that you'll have to build all your object's sizes at runtime based on your new viewport.
There isn't a one way fit all solution for such problems so you'll have to find which one suits your app. You can define your button sizes as % of screen's width or height; Or set them to a fixed value and adjust the spaces between them; or a combination of both(make an object partially bigger and modify the space between them).