Cocos2d-x setContentSize gives poor graphic quality - graphics

I want to create sprite with size is relative to the screen size.
I.e: Sprite size is equal to screen width * 0.2.
I use setContentSize and setScale but it gives ugly and poor graphic quality.
I've read about multiple resolution supports, but it doesn't work on this case because i need sprite size adapt to the any screen size.
Testing on iPhone 7, i scale an image from 512x512 to 64x64.
This is error of cocos2d-x or anyway to archive it?

Scale it accordingly to a device size.
yourSprite->setScale(mainScene->getContentSize().width / yourSprite->getContentSize().width * 0.2, mainScene->getContentSize().width / yourSprite->getContentSize().width * 0.2);
And do not use setContentSize

You can scale your sprite according content scale factor that calculates according to your device screen size and what ResolutionPolicy you're using.
auto sprite= Sprite::create("xyz.png")
sprite->setScale(Director::getInstance()->getContentScaleFactor());

Related

Godot pixelated image

Godot 2d project, I created at 640 640 png using Gimp.
Imported those PNG's to Godot as texture(2d).
After setting scale to 0.1, I resized those images to 64 x 64 in godot scene.
When I initiate this image in my main scene, I get this pixelated disgusting result.
Edit : Dont be confused with rotated red wings, I did it at runtime. Its not part of the question.
My window size is 1270 x 780
Stretch Mode is viewport.
I tried changing import settings etc.
I wonder is it not possible to have a sleek image in this sizes?
Disclaimer: I haven’t bothered to fire up Godot to reproduce your problem.
I suspect you are shooting yourself in the foot by that scale 0.1 bit. Remember, every time you resample (scale) an image there is loss.
There are three things to do:
Prepare your image(s) to have the same size (resolution) as your intended target display. In other words, if your image is going to display at 64×64 pixels, then your source image should be 64×64 pixels.
When importing images, make sure that Filter is set to ☑ On. If your image contains alpha, you may also wish to check the Fix Alpha Border flag.
Perform as few resampling operations as possible to display the image. In your particular case, you are resampling it to a tenth of its size before again resampling it up to the displayed size. Don’t do that. (This is probably the main cause of your problem.) Just make your sprite have the natural size of the image, and scale the sprite only if necessary.
It is also possible that you are applying some other filter or that your renderer has a bad resampler attached to it, but your problem description does not lead me to think either of these are likely.
A warning ahead: I'm not into godot at all, but I have some experience with image resizing.
Your problem looks totally related to pure image resizing. If you scale down an image in one go by any factor smaller than 0.5 (this means make it smaller than half its original size), you will face this effect of an ugly small image.
To get a nice and smooth result, you have to resize it multiple times:
Always reduce the image size by half, until the next necessary step is bigger than scaling by 0.5.
For your case (640x640 to 64x64) it would need these steps:
640 * 0.5 => 320
320 * 0.5 => 160
160 * 0.5 => 80
80 * 0.8 => 64
You can either start with a much smaller image - if you never need it with that big size in your code, or you add multiple scaled resolutions to your resources, or you precalculate the halfed steps before you start using them and then just pick the right image to scale down by the final factor.
I'm not very experienced with godot and haven't opened it right now, but I could imagine that you shouldn't scale the image to 0.1 because then there will be a loss in image quality.

How to make image fit screen in Godot

I am new in godot engine and I am trying to make mobile game (portrait mode only). I would like to make background image fit screen size. How do I do that? Do i have to import images with specific sizes and implement them all for various screens? If I import image to big, it will just cut out parts that don't fit screen.
Also, while developing, which width and height values should I use for these purposes?
With Godot 3, I am able to set size and position of sprite / other UI elements using script. I am not using the stretch mode for display window.
Here is how you can easily make the sprite to match viewport size -
var viewportWidth = get_viewport().size.x
var viewportHeight = get_viewport().size.y
var scale = viewportWidth / $Sprite.texture.get_size().x
# Optional: Center the sprite, required only if the sprite's Offset>Centered checkbox is set
$Sprite.set_position(Vector2(viewportWidth/2, viewportHeight/2))
# Set same scale value horizontally/vertically to maintain aspect ratio
# If however you don't want to maintain aspect ratio, simply set different
# scale along x and y
$Sprite.set_scale(Vector2(scale, scale))
Also for targeting mobile devices I would suggest importing a PNG of size 1080x1920 (you said portrait).
Working with different screen sizes is always a bit complicated. Especially for mobile games due to the different screen sizes, resolutions and aspect ratios.
The easiest way I can think of, is scaling of the viewport. Keep in mind that your root node is always a viewport. In Godot you can stretch the viewport in the project settings (you have to enable the stretch mode option). You can find a nice little tutorial here.
However, viewport stretching might result in an image distortion or black bars at the edges.
Another elegant approach would be to create an image that is larger than you viewport and just define an area that has to be shown on every device no matter whats the resolution. Here is someone showing what I am meaning.
I can't really answer your second question about the optimal width and height but I would look for the most typical mobile phone resolutions and ratios and go with that settings. In the end you probably should start with using the width and height ratio of the phone you want to use for testing and debugging.
Hope that helps.

What dimensional units are used in PyQt4?

When using "setMinimumHeight(...)/setMinimumWidth(...)" what units are the arguments in? I'm not turning up anything online, the book I bought doesn't address it and based on my experiments the units certainly aren't pixels. Thanks in advance.
Those parameters are measured in pixels, but there are other things at play here as well that unfortunately are harder to deal with and may be complicating your measurments.
Take a look at the following two images. The resolution of my screen remains at 3840x2160 but the "Scale Factor" that Windows suggests varies between 100% and 250%.
Scale Factor = 100%
Scale Factor = 250%
The ruler has actually changed size which could give you the impression that the size policy of these isn't equivalent to the pixel size. Note the size of each of these widgets starts at the grey, not at the blue. Additionally, even though Qt maintains the size of the widget in pixels independently from Windows' "Scale Factor", the same can't be said for the label in the center which does change in size depending on the scaling.
I don't know exactly how you are taking your measurements, what the GUI is, or what your display setting is, but those all can contribute to the confusion around sizing in Qt.

PlantUml - Set max width without constraining height

I have a plantUml diagram that looks like this:
The image has a width of 1234px and a height of 970px. I need to print the image as part of a report and would like to fit it on a letter sized sheet of paper in portrait orientation.
If I could set the max width of 900px it would fit better in my report. I don't mind if the diagram becomes significantly longer/taller.
I have tried using various combinations of
scale 200 width
scale 700 height
But as per the doc, this doesn't do what I want:
You can use the scale command to zoom the generated image.
You can use either a number or a fraction to define the scale factor.
You can also specify either width or height (in pixel). And you can
also give both width and height : the image is scaled to fit inside
the specified dimension.
How can I set a max width for my diagram, without changing the font sizes used or constraining the height allowed for my diagram.
I'd go a different route with this. Create the diagram however you please and use the dpi skinparam to scale the image up or down when printing, for instance skinparam dpi 300
The default is 96 dpi but I've had to go up to as much as 600 to get a decent result.

Scale the iPad resolution images to fit android resolutions

Client just provided us with the iPad source code which contain all the images with 1024X768 resolution now I want to convert them to the android drawables i.e
480*854
320*480
1280*800
I know I have to use 1.5 as scaling factor to convert hdpi to xhdpi and mdpi to hdpi.
but with this iPad resolution what resizing factor shall I use?
just the scaling factor to xhdpi would be helpful thanks.
I figured it out myself in order to convert iPad images to android resolutions here is the scaling factors
For Hdpi
width Scaling factor--------------0.625
Hieght Scaling factor---------------0.833
For xhdpi
Hieght Scaling factor--------------1.25
Width Scaling factor---------------1.04
For mdpi
Hieght Scaling factor--------------0.468
Width Scaling factor---------------0.416

Resources