Ok, so I've already waded through a bunch of questions around this, and it's just making me even more confused.

Let's say I am trying to model a card table in a 2d game. Behind (beneath) the table is a quad with a floor texture. The "table" is a sprite that is just an oval (using basic shapes at this stage until I have real artwork).

I've read plenty of questions on how to scale to different device resolutions. And, that is certainly one way to do it (bit seems like a lot of work). I've also read posts about changing the size of the orthographic camera to match the device (this seems easier). But i'm left not quite understanding what the frame of reference is.

Let's say I design the game to work in 16:9 at HD resolution (1920x1080). I size the "floor" to fill the entire space (and maybe extend a little beyond). I size the "table" to fit within a smaller portion of that space.

If you have a fixed scene (ie, not a scroller), and you want the contents to fill the entire viewport, what is the best way to go about this? Scaling the objects, scaling the camera?

As far as units, what's the best choice? 1 PPU? What rule of thumb do you use when choosing PPU? What are the reasons to choose different PPU's?

I think i'm missing the forest for the trees. I understand so many of the basic concepts from reading so many questions, I just don't know how to put them together and when to choose which method.

  • \$\begingroup\$ For choosing a PPU setting, it's arbitrary and up to you, just don't use 1, for the reasons outlined here. Your PPU should be some number that's meaningful in your game, like the number of pixels across one of your tile assets in a tile-based game, or the width or spacing of your cards in a card game. That way the objects and spacings you use most often come out as small, simple numbers in world units ("I'll move this card over 1 slot, that's x += 1.0f") \$\endgroup\$ – DMGregory Oct 12 '18 at 13:51

When your game is rather UI-heavy (you have lots of buttons, text fields and containers which hold card images) then you might want to consider to build most of your game with the UI system. It is pretty well-equipped to handle responsive layouts which automatically fit to the screen size and aspect ratio (See the layout elements for details).

But if you prefer to use objects in world-space instead, then your primary tool to control how much of the screen is visible is the camera size. The camera output will render that amount of view-space by sampling it in the current screen resolution. The size of the camera is the vertical size. The horizontal size is derived from the screen aspect ratio.

So if you have an orthographic camera pointing at 0 : 0, your camera size is 5 and your horizontal to vertical ratio is 1.777 (16 divided by 9), then your visible world area reaches from -8.888 : -5 to 8.8888 : 5.

If you are using a perspective camera, it gets more complicated, because you need to take distance and FOV angle into account. But you said you are creating a 2d game, so you are likely not using a perspective camera anyway.

If you want specific images to appear larger or smaller, then there are two ways to control this:

  • The "pixels per unit" value in the import settings of the image asset. For example, if you have a 128px by 256px card image, and you want that image to cover 1 unit by 2 units in your game world, you would set the PPU value to 128.
  • The scale-values in the transform of the game object.

I would recommend you to go with the first variant, unless you want certain objects to be larger or smaller than usual. The usual intention of scale is that a scale of 1 means "normal size" (whatever "normal" means in the context of your game). You might notice that any new object you add to the scene starts out with a scale of (1:1:1). So if you want another value than 1 to be the "normal" value, then you will have to adjust it for every new game object manually, which would be inconvenient.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.