2
\$\begingroup\$

Let's say I have a texture atlas of an entity A which is 950x800, each frame has a size of 95 (width) and 100 (height) in pixels. Additionally, I have a 2150x1300 atlas, which contains more frames. It belongs to an entity B which size in pixels is 100 (width) and 80(height).

Since the atlases have different resolutions, I need to apply correct scale matrices to the entities so they will fit their ratio in pixels. Obviously I can divide dimension of A by dimension of B and calculate matrix size for one of them according to the division.

This approach may seem fine at first, however it makes the whole game set of entities dependent on dimensions of a single entity.

What I want is the unique source of truth which I will use to scale entities knowing their dimensions in pixels.

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

Looks like your assets come from different sources and are not "syncronized". For the prototype or MVP it doesn't matter that much. Once you have a solid game on your hands you will probably have to replace them with something made to the spec anyway.

Typically you would want to have assets displayed well at x1 scale. What is that scale going to be - depends on your taste and style. E.g. Factorio has a default scale where all the sprites are rendered pixel-to-pixel on to the screen. This scale is arbitrary. They decided that terrain grid is NxN pixels and went from that. Usually it makes some sense to base the grid off of something divisible by 2, e.g. 32 or 48 or 64, just to simplify math operations and atlas packing.


Supporting different resolutions is another can of worms, where you decide if you want to show more stuff on the screen (e.g. like Factorio) or draw things proportionally larger pixel-wise (typically preferred by mobile games, since all the smartphones screens are so different).

See this answer addressing such terms as pixel density (texel per screen area / world unit) for further reading.

\$\endgroup\$
6
  • \$\begingroup\$ I am not really sure what is meant by "synchronized"? Does that mean that all texture atlas files should have the same dimensions? \$\endgroup\$ Commented Aug 21, 2024 at 13:57
  • 1
    \$\begingroup\$ See this answer — it's phrased in terms of Unity, but it's addressing the same issue. It does not matter how big each sprite is or what size its atlas is. What matters is the "texel density": how many sprite texels are displayed in a given chunk of your game world or screen. So if you have one asset whose sprite is 32 pixels tall and another one that's 48 pixels tall, that's fine if you want the second sprite to be 50% taller than the first on screen. But if you want them both to fit in the same height (like a tile), then they're mismatched. \$\endgroup\$ Commented Aug 21, 2024 at 15:12
  • \$\begingroup\$ @DMGregory so is it fine to scale every other entities dependent on the size of a character e.g. to match real ratio of heights and widths? \$\endgroup\$ Commented Aug 21, 2024 at 15:29
  • 3
    \$\begingroup\$ You're free to decide what "one unit" is in your game. If that happens to be "exactly one George tall" that's no more arbitrary than any other choice. If you care about pixel perfect rendering, you'll want to ensure that makes an integer ratio of screen pixels per sprite texel at the screen/window resolutions you support. \$\endgroup\$ Commented Aug 21, 2024 at 16:07
  • \$\begingroup\$ @Kromster hi, sorry for reaching out to you in the comments, but I wanted to address you some question in Discord. I've sent you a request to chat, but seems like you didn't see it \$\endgroup\$ Commented Oct 26, 2024 at 15:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.