How to set screen resolution in unity and then scale to fit window size - unity3d

Trying to get Gameboy resolution which is 160px x 144px in unity and then the game will scale up when in full screan with bars around the side where the aspect ratio doesn't fit. But it still only has 160 "pixels" just scaled to take up however many pixels it takes

You could start by reading the documentation file on "Resolution and Presentation"
here is the link: https://docs.unity3d.com/Manual/class-PlayerSettingsAndroid.html#Resolution
and this forum page also seems to be helpful:https://forum.unity.com/threads/target-dpi-vs-render-scale-vs-resolution-scaling-fixed-dpi-factor-vs-setresolution.1076789/
Now based on these two I would consider this to be your solution:
Go to Edit > Project Settings > Player (on the left list) > Resolution and Presentation
once you are here find the Resolution Scaling Mode option and set it to Fixed DPI as shown in this Image
Once you do that you get the option to choose a number between 30 to 1000, which you would decide based on the output screen you target. If the number you set is lower than the screens native dpi, your game will upscale and by the same reasoning, I would say it would downscale if you set it higher than the native dpi of the target screen. I am not 100% sure this is the solution to your problem, but I hope it sets you up on the right direction.

Related

UI is shown too small in final (built) game

I'm a newbie to Unity and am learning. I've made my first game which is a simple platformer, along with a main menu. The game also has some text GUI elements. When I run it in Unity's built-in player, the GUI looks fine, but when I build the project and run the game using the .exe, the UI is scaled down.
I'm attaching some screenshots below to clarify this.
(As seen in Unity player)
(As seen in game)
Also, the game UI also looks scaled down:
(As seen in player)
(As seen in game)
I want the in-game UI to be exactly like the one seen in the Unity player.
How do I fix this?
The Canvas can be set to scale with different settings if you want it to be accurate you should choose:
-Scale With Screen Size
Using the Scale With Screen Size mode, positions and sizes can be specified according to the pixels of a specified reference resolution. If the current screen resolution is larger than the reference resolution, the Canvas will keep having only the resolution of the reference resolution, but will scale up in order to fit the screen. If the current screen resolution is smaller than the reference resolution, the Canvas will similarly be scaled down to fit.
1- Go to your Canvas and select the Scale With Screen Size option
2- After that, make sure that the Reference Resolution is the same as the Game Window resolution in your Unity layout, I leave here an example:
As you can see, the resolution set on my Game window is (1024x768) and the reference resolution of the Canvas too.

Why is my pixel art scaling wrong on other resolutions?

My pixel art assets all have a ppu of 32 and i have applied that to them all.
On 1920x1080, the resolution is fine, but most other resolutions the sprites pixels are squashed and stretched. I also have set the correct camera size using vertical resolution / PPU / 2). I have also used other formulas and they all give me the same camera size so i'm sure that's not the issue.
I have two moniters, one at 1920x1080, and one at 1360x768, and that moniter is where it scales wrong. Is there a way i can keep the pixels scaling the same across all resolutions? I have tried the pixel perfect camera and this doesn't fix my issue either.
https://imgur.com/gallery/Uf8YqNi Here is a sample of both resolutions, if you open them in a new tab and zoom in on the sprite you can see how tey get distorted in the 1360x768 screen.
Filter mode should be Point and compression None. If this doesn't fix it, then you should use Pixel Perfect camera. It will help you with the animations to be pixel perfect as well.
Window -> Package Manager -> Advanced -> Show preview packages -> 2D Pixel Perfect -> Instlal. Then you just add Pixel Perfect Camera component to your Camera.

Unity blurry and pixelated sprites in editor (no pixel art)

I am currently making a mobile match-3 like game in unity. I have made all the graphics for the gems(the objects with which you make the matches) in Inkscape at 256x256 and exported them(PNG Files) with 90 dpi(also tried with 360 but nothing changed). My problem is that when I run the game in the editor the graphics seem to be "pixelated" and blurry. In my sprite settings I've set Pixels per Unit to 256, checked Generate Mip Maps, I am using Bilinear Filter Mode and the aniso level is 0. I have also set the max size to 256 and compression to high quality(My Main Camera's size is 10 but I tried to change that and nothing changed as far as the quality of the sprites). What can I do to "perfectly" display my sprites? Do I have to export them in some other way from Inkscape or do I have to change some Unity's settings?
Thank you.
NOTE: My sprites are not "pixel art"!
Edit(Added photos of the purple gem as file and how it is shown in editor):
Because scaling
You're display resolution on the images isn't a 256x256 region where those images are displayed, which means that they must be scaled in some manner in order to display in the desired region. Camera rendering is notoriously bad at scaling. As your images aren't Vector (and Unity doesn't support vector graphic formats anyway), scaling will always result in a loss of detail. Detail like hard edges.
Your options are:
smaller images where you have complete control over how the image is scaled down
bilinear filtering (which is fundamentally blurry)
mipmaps (which are automatically scaled down versions of your image in powers of two)
If the later two aren't giving satisfactory results, your only option is the first.

Unity 2D art is blurry

For some reason, I can't get these tilemaps to come out like they were created in Unity...
The pixel art is imported to Unity from Tiled.
The pixel art in Tiled:
The same pixel art imported to Unity:
Does anyone have any idea how I can fix this?
Thanks in advance!
As requested, the sprite import settings:
Posting my comment as an answer after all.
As I suggested, one way to get rid of blurring is to set the "Filter Mode" of the sprite to "Point (no filter)" instead of "Bilinear" or "Trilinear"
Here you can see the difference between bilinear and point filtering.
If that doesn't help, try messing with the quality settings in the Sprite Import.
Increase the "Max Size" and maybe disable "Compression" or increase the quality of the compression.
Here you can see differences between the different compression qualities, ranging from "Low" over "High" to "None"
You can also try to increase the "Max Size" value for higher quality sprites. It scales the dimensions of your sprite to not exceed the specified value. If your sprite sheet is already smaller than the "Max Value", increasing it will have no effect though.
The next picture shows the differences between Sizes 512, 256, 128 and 64 for a Sprite with dimensions 423 x 467
You can see that sizes above the dimensions won't have any effect, whereas smaller values will scale the sprite down, decreasing its visual quality.
Usually fiddling around with those values should help making your sprites look sharp and not blurred anymore.
EDIT:
As #NikaKasradze pointed out, there are also default quality settings you can try. Go to Edit > Project Settings > Quality
The matrix on top gives you a selection of all current quality levels for the Editor itself as well as all build target platforms. The green tick shows what currently is selected as the default quality. You can also set the "Texture Quality" which defines the overall texture resolution in your project. You can choose between "Full", "Half", "Quarter" and "Eight Res". You should choose "Full Res" for your current default settings.
Considering you already changed the filtering from Bilinear to Point (no filter), the issue may be that Unity compresses your texture by default. This is likely if it is a POT texture (Power of two resolution).
You can override this for individual platforms at the bottom of the texture's import settings. Select RGBA 32 bit if you need the alpha channel (transparency) or RGB 24 bit if you don't, to get your texture uncompressed.
And don't forget hitting that Apply-button! ;)
If this doesn't help, could you post a picture of your import settings?
Also, what data type is your image?
EDIT:
After the import settings screenshot has been added, it seems to me the issue lies in the SpriteMode settings.
As far as I understand, the image used is a Spritesheet in form of a tilemap. Therefore the SpriteMode should be set to Multiple.
You can then click on the Sprite Editor button and cut the sheet into individual sprites using the Slice function (now separate, as of Unity 5.6).
You probably want to use the Grid - By Cell Size method, which is basically how this is handled inside Tiled.
You also want to adjust your Pixels Per Unit setting to match the resolution of your tiles (for pixel-perfect results).
I had some issues with blurry sprites and I was able to fix it by changing the resolution of my sprites in an image editing software. The resolution was 576x352 and I changed it to 512x512 and that fixed it. I think its best for Unity that images are square and have a resolution that is a power of 2 as often as possible (for example 512 = 2 ^ 9).
Make sure you disabled Mip Maps:
http://prntscr.com/eup3hd
After literally hours of tinkering, the only solution I could come to was to open photoshop and export the tilemap at 4000% its original size.
There is still some minor blurring if I zoom in but at least it isn't as bad as I demoed in my question.
I have tried everyone's answers here to no avail, I am left with the conclusion that it must be a Tiled2Unity problem (despite it never doing this before)
I will update this post if I find a solution...

Strategy to create a screen resolution independent java desktop application?

I have been been programming with java using eclipse for a few months and would consider myself at an intermediate level, and i have a vb.net background originally.
I have a question about screen resolution( in pixels) and auto-scaling my application with two parts
A) When you design a desktop application with swing( or JavaFX ) do you actually calculate the pixel width and height of every single component and then scale it up or down in code by detecting the screen resolution at startup? Scene-Builder for JavaFX, Eclipse Windows Builder Gridbag layout and GroupLayout have the facility to do it with a couple of clicks, and it is relatively easy . If it IS calculated and handcoded then that means I'll have to spend a lot of time planning ahead for each control.
B) Is there a common consensus over a screen resolution ( 1024x768 e.g.) to design the application for "initially" ( and then scaling all controls according to detected screen resolution)? My monitor has 1920x1080 resolution but I am confused which resolution should i begin designing my application in. 1024x768 seems reasonable to me.
Thank you very much for your time
I've done all my work in Java Swing, so this might not be appropriate for other GUI sets.
Layout all the components within panels and one frame.
Pack the frame.
Print out the size of the frame.
If the frame is too big, put some components in a scroll pane.
Repeat until the frame is the desired size.
In other words, I'm concerned with the functionality of the GUI. I don't care how big it is, unless it's too big for a display.
I put together an alarm clock that has a frame of 170 x 152 pixels. It sits in the lower right hand corner of my display.
I put together a clock / calendar that has a frame of 1097 X 522 pixels. It sits in the upper right hand corner of my display.
I put together a Cobol Paragraph Structure display where I maximized the frame to the size of the display, mainly so the paragraph name tree had the maximum amount of space.