0
\$\begingroup\$

Let's say I want to make a 2D game and I'll use a spritesheet containing all of the animation frames and a texture-atlas for static sprites such as walls, non-animated decorations...etc.

Should I create separate image objects for all the static sprites and for all animation-rows or should I just pass the on-texture-atlas (or on-spritesheet) coordinates for them?

Which solution, or "direction" is considered elegant in game-development?

Thanks for the help! :)

Some pseudocode:

Separate image objects:

Class StaticSprite {
  Image texture;

  // ...

  public Image getImage() {
     // ...
  }

  public static final CheckedWall cw = new CheckedWall( -- checked wall grid extracted from the texture-atlas -- )
  public static final WoodWall ww = new WoodWall( -- wood wall grid extracted from the texture...
}

Or:

class StaticSprite {
 int texX, texY, size;

 // ...

 public Image getImage() {
    // gives the part of the spritesheet
 }

 public static final WoodWall ww = new WoodWall( -- coordinates for the texture-atlas -- )
}

Assuming that the spritesheet is accessible for all these sprite-related classes.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Most of the time you should go for a hybrid approach, seperating by character\tileset\what have you.

This way you dont have to load up a giant file, which would be much slower if you dont load the full game graphics all at once, and would use up less memory at once.

\$\endgroup\$
5
  • \$\begingroup\$ So find the balance in size by using more, not giant sheets AND do the load from sheet by coordinates approach? I give it a try, thanks :) \$\endgroup\$
    – atanii
    Aug 9, 2018 at 19:20
  • \$\begingroup\$ Exactly! I tend to go a bit further and have animation config files for each file that describes different things and the such, so you have a lot of room to play around in haha \$\endgroup\$ Aug 9, 2018 at 19:23
  • \$\begingroup\$ By that i mean say you have all the things for the main character in one file, and have different animations vertically whiel the frames are horizontal, and depending on how comfortable you are wih parsing files and the such loading animation names, frame counts and the such from a config \$\endgroup\$ Aug 9, 2018 at 19:25
  • \$\begingroup\$ Depending on how giant the images are, I don’t think it’s necessary to worry about speed or memory usage for one or a few images, especially on modern hardware. Everything in one texture means less work for the GPU. It also means you can have very few draw calls if you can batch them together. In fact, if everything is it in one texture, you could get down to a single draw call, hypothetically. \$\endgroup\$
    – Ed Marty
    Aug 10, 2018 at 14:03
  • \$\begingroup\$ True modern hardware can support it fairly well, but if you get down to just one file and have all assets for your full game on that one file it would be a pain to work with, not only cause of the loading but also cause any other Tools you use to modify those assets would need to open it and may not be efficient, updating the game you automatically need to redownload the full asset file instead of only updating the couple assets that are needed, etc... \$\endgroup\$ Aug 10, 2018 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .