Question

So when making a 2D game there is a common pattern of creating objects and setting the sprites for each object. Some objects have many sprites, some have only 1.

There are 2 obvious ways to handle this.

  1. Create a SpriteManager class to pull in all of your sprites and send them off to each of your classes.

The problem with this approach seems to be that you must then create unique interfaces for each class to pass it the sprite(s), since each may use an arbitrary number of sprites.

  1. Send each class a reference to the resources it needs to pull in its own textures and handle everything inside the class.

Doing this allows you to extend a basic sprite class and save yourself time by only having one sprite setter function to write and be inherited by all children.

So my question is just which is better and why?

Was it helpful?

Solution

To answer my own question it is better to create some sort of sprite manager that knows about all the sprites.

The problem with sending an object the tools it needs to load textures is you may end up loading the same texture multiple times if you have multiple instances of your object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top