0

I am going to have lots of (same looking) zombies in my game.

Is it a good idea to make the texture static, so that SpriteBatch wont need to load a new texture?

I go through the whole zombie list and draw every zombie with the same call, just changing the position. Will SpriteBatch get it? That its exactly the same texture every time? Where could be the disadvantage?

Cyral
  • 13,999
  • 6
  • 50
  • 90

1 Answers1

2

I don't think that the use of static will give you some kind of benefit.
What's sure is that, if you load your Texture2D only once, you save memory and you can draw it how many times you need using the same variable.

Anyway, if you're using only one texture you don't have any problem, because:

Each instance of ContentManager will only load any given resource once. The second time you ask for a resource, it will return the same instance that it returned last time.

ContentManager maintains a list of all the content it has loaded internally. This list prevents the garbage collector from cleaning up those resources.

Reference here.

Community
  • 1
  • 1
pinckerman
  • 4,115
  • 6
  • 33
  • 42