Jump to content
  • Advertisement
Sign in to follow this  
Forenkazan

Unity Creating a game for multiple devices (resolution and aspect ratio problem)

This topic is 1378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

 

i am going to create a new 2D game by using Unity and C#

 

however i want my game to be for pc/ios/andriod devices, but as you know every device has its own resolution and aspect ratio.

 

so what is the better way to do a game for all of the devices without corrupting the images

 

someone told me to work in the highest resolution and aspect ratio available and just shrink your images later.

 

but i dont know if thats work and i dont know what is the highest resolution and aspect ratio for ios/android.

 

 

Thank you very much.

Edited by Forenkazan

Share this post


Link to post
Share on other sites
Advertisement

Scaling artifacts are horrible.

 

I have tried many different ways of handling variable resolution and I'm sorry to say there is no magic bullet

 

You have to make a value judgement on every part of the game.

 

3D is not a problem, you just have to be careful about mipmap distances, other than that it's fine.

 

2D is an issue.

 

For some parts of the game I typically store several versions of each graphic and load the one that is closest to the dispay resolution, other parts I use scaling, some parts I use construction.

 

Construction is where you store a single graphic, but pull it apart in rendering. For example a GUI frame. Instead of just blitting the image onto the screen I would render the fill, then the edges, then the corners. This way you haven't scaled any graphics in the blit, the corner is say 16 by 16 in the bitmap and 16 by 16 on screen. However you have to do multiple blit's when you would normally do one.

 

Sorry, no easy solution.

Share this post


Link to post
Share on other sites

In 2D mode, Unity auto-scales so that the height is preserved (you don't have a say about it), and it clips by width to fit the aspect ratio.

 

I'd second your friend - start with a high resolution and a specific aspect ratio. Later on, you can hide certain elements, or move other elements you need to be at the edge. I've found that programming in Unity for different aspect ratios is not such a pain in the ass. I expected a lot worse :)

 

To make this work, create a big background - bigger than any resolution you'd normally support. Put at (0,0,0) - so that it is always centered. Make objects children of each other. Create a script that will position its GameObject at the proper edge (top|bottom, left|right) with random offset (x,y) when the scene is initialized (Start). You can use the main camera's aspect ratio (Camera.main.aspect) to determine the proper coordinates. Have in mind that origin in Unity is by default (0.5, 0.5) and that it uses Cartesian coordinates instead of the typical (0,0) for top-left corner of screen. Also, the default mapping is 100pixels=1 unit. Don't forget to set-up your orthographic camera for your default resolution (it's size is your default resolution's height / 200).

 

We use this and additional tricks to move objects proportionally (up to a point) for a second project, and it works quite well so far. The cool thing is that you can test it in the editor itself. The only problem with this approach (dynamic location by x based on aspect ratio) is that you need to run the game to see objects in their real position.

Share this post


Link to post
Share on other sites

In 2D mode, Unity auto-scales so that the height is preserved (you don't have a say about it), and it clips by width to fit the aspect ratio.

 

 

the game i am going to make is 2D, i made a  2D game before and unity didnt auto-scale any images/sprites for me.

 

is there an option for it ? or is it a feature for unity pro?

Share this post


Link to post
Share on other sites

Scaling probably isn't quite the correct term. First, you must develop for a specific resolution. Say, 1,280 × 720. Then you must set-up your orthographic camera's size in the editor. Since your development resolution is 720p, then the size is h/200 = 3.6.

 

If you develop for that resolution - that is - create textures and position them, not caring about resolution, the effect will be as follows:

  • Regardless of actual deployed screen size/resolution/aspect ratio, Unity will make sure that the y of your objects will remain as it looks in the editor
  • If the device's aspect ratio > the one you programmed against (>width), you will have extra space to the left and to the right
  • If the device's aspect ratio < the one you programmed against (<width), some things will be clipped to the left and to the right

This is why your background (and any parallax effects) must be a lot bigger than your target resolution (to cover bigger aspect ratio), and this is why you need a script to move objects (to the left or to the right). You can calculate how much based on Camera.ratio and Camera.size.

Share this post


Link to post
Share on other sites

another option is to use a virtual coordinate system API, say 10000x10000. all 2d drawing calls use the API. the API converts to hardware coordinates as needed, based on the current resolution. it also calls the appropriate graphics library routine, based on the underlying graphics engine used. sprites are as large as possible, and scaled down using high quality sampling. lower resolution versions may also be used, with the API automatically selecting the best available for scaling. but you still need to deal with widescreen vs non widescreen resolutions with letterboxing to get the intended original aspect ratio at all resolutions.  scaling down - not up, high quality scaling algo's, and multiple resolutions for source images (almost like mipmaps) help keep artifacts to a minimum. best of all, you can write all your 2d code to the API, then plug in any graphics engine at any resolution underneath it.

Share this post


Link to post
Share on other sites

For simple things like sprites, just create a series of them at different resolutions, choose the one larger than you need, use a high quality down-sampling filter to reduce to the correct size, then add a small amount of sharpening.

 

For textures that need to tile, do the same as above, except add a few pixels from adjacent tiles before you down-sample and sharpen. Then "cut out " the correct size you need: For example, say you have a series of tiles created at 64x64, 32x32 and 16x16, but you need one at 48x48 (64 / 1.333. = 48). Use the 64x64, add 4 pixels either side from adjacent tiles (or top/bottom) to make it 72 pixels wide, reduce by 1.333333 to 54x48 pixels , then chop of the extra the extra 3 pixels from each side. If you don't do this, the down-sampling or sharpening filters may leave visible borders at the edges.

Edited by mark ds

Share this post


Link to post
Share on other sites

For my 2D games on android, I support various screen size . I also supported various screen ratio once, but I decided to not support that from now, as it can be tedious to accomodate different screen layout.

 

Anyway, to support various screen size :

  • I generate one set of assets per screen definition (qHD, HD, FHD, QDHD). Note that i write screen definition instead of size because i will use the same screen definition for not so different screen sizes. e.g : 1024x600 will use qHD (960x540), as well as a qHD screen troncated because of the Android onscreen button bar (a case I had to deals with, very bad surprise).
  • In the program, I use the size of my elements for the used screen definition, and the reference size of the screen definition (e.g : qHD-->960x540), so that it's always adjusted to the screen.

Share this post


Link to post
Share on other sites

I don't intend to hijack this thread, but I have a similar question. Any responses are much appreciated, and hopefully it helps answer some of the questions OP has.

 

So I'm making a 2-D platformer that I want to have highly reminiscent of platformers from the 16-bit era, especially graphically. What I've done is created a number of rooms and sprites, which are composed of 16x16 pixel tiles. The issue is that people now-a-days are playing games on 1080p monitors, not the old-school small resolutions TV's of the 90's. What would be the best way to get the 16-bit feel on one of these monitors? I'm only using SDL as my API; I haven't explitly written anything for OpenGL yet. When I'm rendering, say, my character which is 2 tiles high and 1 tile wide (32x16 pixels), the SDL render function renders the character to be a given fraction of the total screen size that I've set. For example, if I want my character to be 1/16th of the screen width and the screen is 512 pixels wide, the character will be 32 pixels wide. This means that SDL has to upscale the sprite, which I've drawn to be 16 pixels wide, up to 32 pixels wide. SDL seems to do this, although there are distorting effects at certain screen sizes. For example, if I increase the screen to a certain size it no longer looks like the character is standing flush on the ground; there will be a small sliver of white background between my character and the floor. Any idea on how I should handle this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By Alexander_Vovk
      Hello Guys!
      Please share your experience, where is it better to find sales manager  specialists for indie team of 6 + people(remotely)?
      Maybe someone has a good experience of cooperation with finding projects through sale managers(USA and Canada)?
      Thank you
      Best Regards
      Alex Vovk
      Co-Founder of Sixteen Squares
      Alexander_Vovk@outlook.com
       
    • By RoKabium Games
      Been a bit quiet recently, but we've been busy bug fixing and tweaking things... Now we have lots more 'Particle effects' in the game, specifically here the Flamethrower and Enemy attacks!
    • By JoshuaFraser
      Hi and thanks for reading, I have an issue with this reactive crosshair script, everything works fine until I start changing the offset. Give the script a go and you will see what I mean, when I do SetOffset(0f); it doesnt always set back to the origional state, if anyone can spot a fix I'd be super appreciative!
      using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReactiveCrosshair : MonoBehaviour { [SerializeField] GameObject c_limb_prefab; private float center_offset = 0f; private float current_offset = 0f; private float max_offset = .5f; private int number_of_limbs = 4; private float limb_length = .05f; private float limb_width = .005f; private List<GameObject> c_limbs = new List<GameObject>(); public void SetupCrosshair(){ for (int i = 0; i < number_of_limbs; i++) { GameObject line_go = (GameObject)Instantiate (c_limb_prefab); line_go.transform.SetParent (this.transform); Vector3 limb_pos = new Vector3 (0f,0f,0f); //line_go.transform.position = limb_pos; line_go.transform.localPosition = limb_pos; LineRenderer line = line_go.GetComponent<LineRenderer>(); line.startWidth = limb_width; line.positionCount = 2; line.SetPosition (0, line_go.transform.localPosition + new Vector3(center_offset, 0f, 0f)); line.SetPosition (1, line_go.transform.localPosition + new Vector3(center_offset + limb_length, 0f, 0f)); line.useWorldSpace = false; c_limbs.Add(line_go.gameObject); } if (c_limbs != null) { OrientLimbs (); SetOffset (0f); } } public void OrientLimbs(){ for (int i = 0; i < c_limbs.Count; i++) { float rotation_step = 360f / (float)c_limbs.Count; c_limbs [i].transform.RotateAround (c_limbs[i].transform.position, c_limbs[i].transform.forward, 90f + (rotation_step * (float)i)); } } public void SetOffset(float _current_spread){ float offset = Mathf.Lerp (0f, max_offset, _current_spread); for (int i = 0; i < number_of_limbs; i++) { if (offset > current_offset) { Vector3 pos = c_limbs [i].transform.position + (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } if (offset < current_offset) { Vector3 pos = c_limbs [i].transform.position - (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } } Debug.Log ("SetOffset() offset: " + offset.ToString () + " _current_spread: " + _current_spread.ToString() + " localPos: " + c_limbs[1].transform.localPosition); current_offset = offset; } }  
    • By Erik Nivala
      So, as the title says i am trying to figure out a good way sync all that information with other players in Unity. My problem is that i can't come up with a good solution since i am used to creating classes for everything e.g. attachments are its own class and then the weapon would save a reference to that attachment. But since you can't send custom classes over [Command] & [ClientRPC] i am a little stuck. A solution for this would be giving each attachment for a slot a unique ID and then passing the ID to other player but i feel like that is very error prone if other ppl add a new attachment or the IDs get mixed up.
      Is there a "standard" way that this is usually done that i am missing?
      I am fairly new to programming so any help is appreciated!
    • By MintyLyton
      I'm looking for any team / people that need a programmer for their project. I'm looking to expand my portfolio which you can see Here. I'm more experienced with Unity but I can spend the time to learn new Engines if that's your preference. I have worked on Unreal Engine 4 before but I might take some time to re-learn it, if the project requires it. Feel free to DM here or use the contact info on my website. 
    • By ethancodes
      I'm working on a system for my game that will allow the player to stack pick ups in a queue. As one pick up expires, the next automatically activates. I'm having an issue though where if I pick up the first one, it activates fine, but if i pick up a second directly after it, it overrides the first one, activates the second one, and then once it has run it's course, everything goes back to normal gameplay, no first pick up. I'm not sure why this is happening. Hopefully someone can spot what I'm doing wrong in my code.
      Here is the code for the pick up manager:
      // Update is called once per frame void Update () { if (pickUpQueue.Count != 0 && !pickUpActive) { pickUpActive = true; pickUpQueue[0].ActivatePickUp(); } DeactivatePickUp(); } void DeactivatePickUp () { if (pickUpQueue.Count != 0 && pickUpActive) { Destroy (pickUpQueue [0]); pickUpQueue.RemoveAt (0); pickUpActive = false; } } And here is the PickUp:
      public override void ActivatePickUp () { ball.GetComponent<Ball>().Speed = 2.0f; //increase ball speed... ball.GetComponent<Ball>().StartCoroutine(timer); //...set time that power up is active }  
      There is also a Base Pick Up:
      public void OnCollisionEnter2D (Collision2D collision) { Vector2 tweak = new Vector2 (Random.Range(0f, 0.2f),Random.Range(0f, 0.2f)); this.gameObject.GetComponent<Rigidbody2D>().velocity += tweak; //if the pickup makes contact with the paddle or ball.... if (collision.gameObject.tag == "Paddle" || collision.gameObject.tag == "Ball") { GameObject.FindObjectOfType<GameManager>().GetComponent<PickUpManager>().pickUpQueue.Add(this); Destroy(gameObject); //...and finally destroy power up object } } As a side note, I am trying to find a solution to this that will work for all of my pickups. Some pickups are ammo based, some are timed. 
    • By D34DPOOL
      Edit Your Profile D34DPOOL 0 Threads 0 Updates 0 Messages Network Mod DB GameFront Sign Out Add jobEdit jobDeleteC# Programmer for a Unity FPS at Anywhere   Programmers located Anywhere.
      Posted by D34DPOOL on May 20th, 2018
      Hello, my name is Mason, and I've been working on a Quake style arena shooter about destroying boxes on and off for about a year now. I have a proof of concept with all of the basic features, but as an artist with little programming skill I've reached the end of my abilities as a programmer haha. I need someone to help fix bugs, optomize code, and to implent new features into the game. As a programmer you will have creative freedom to suggest new features and modes to add into the game if you choose to, I'm usually very open to suggestions :).
      What is required:
      Skill using C#
      Experience with Unity
      Experience using UNET (since it is a multiplayer game), or the effort and ability to learn it
      Compensation:
      Since the game currently has no funding, we can split whatever revenue the game makes in the future. However if you would perfer I can create 2D and/or 3D assets for whatever you need in return for your time and work.
      It's a very open and chill enviornment, where you'll have relative creative freedom. I hope you are interested in joining the team, and have a good day!
       
      To apply email me at mangemason@yahoo.com
    • By davejones
      Is there a way to automatically change the start position of an animation? I have a bunch of animations set up on 3D models in unity. The issue is that I need to move the 3D models, however when I do so the animation start positions are not updated and I have to do it manually.

      Changing the transform of key frames is time consuming with the amount of animations I have, so I was wondering if there was a way to do it automatically?
    • By MoreLion
      hey all! We are looking for members for our Unity horror game! 
      Here’s the story:
      After a deadly virus plunges the world into chaos killing 85% of the human population there are now what they call “zones” these zones are watched very closely by the surviving government, people are checked every day for the virus, even if you touch the spit or any human waste or fluids of the victim who is infected, you will die. But one day, people in the west zone start to go missing, 1 woman goes outside the walls to uncover the mystery, is there more to the virus than meets the eye?, That is where your story starts.
      This game is not a long development game, I have loads other game ideas,
      I will also allow you to have a bit of creative freedom if you wish to add or share a idea!
      And no, it’s not a zombie game lol I feel like zombie games are too generic, in this game you will encounter terrifying beasts!
      There is some concept art one of our concept artists have made
      If interested email liondude12@gmail.com
    • By Canadian Map Makers
      GOVERNOR is a modernized version of the highly popular series of “Caesar” games. Our small team has already developed maps, written specifications, acquired music and performed the historical research needed to create a good base for the programming part of the project.

      Our ultimate goal is to create a world class multi-level strategic city building game, but to start with we would like to create some of the simpler modules to demonstrate proof of concept and graphical elegance.

       

      We would like programmers and graphical artists to come onboard to (initially) create:

      A module where Province wide infrastructure can be built on an interactive 3D map of one of the ancient Roman Provinces.
      A module where city infrastructure can be built on a real 3D interactive landscape.
      For both parts, geographically and historically accurate base maps will be prepared by our team cartographer. Graphics development will be using Blender. The game engine will be Unity.

       

      More information, and examples of the work carried out so far can be found at http://playgovernor.com/ (most of the interesting content is under the Encyclopedia tab).

       

      This project represents a good opportunity for upcoming programmers and 3D modeling artists to develop something for their portfolios in a relatively short time span, working closely with one of Canada’s leading cartographers. There is also the possibility of being involved in this project to the point of a finished game and commercial success! Above all, this is a fun project to work on.

       

      Best regards,

      Steve Chapman (Canadian Map Makers)

       
  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631397
    • Total Posts
      2999810
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!