lawls
lawls

Reputation: 1508

Avoid loading textures more than once

What's the ideal way to load textures? I'm writing a simple RTS game. I have a 2d array that represents the game area. Let's say each array index should be grass. Then I'd do like this:

array[0] = new Grass(x, y);
array[1] = new Grass(x, y);
...

// Constructor for grass
public Grass(int x, int y) {
    loadTexture("grass.png");
}

From the code above you will realize that the grass texture is being loaded twice, which is pretty stupid. How should I tackle this problem? How should I structure my project to avoid this?

Upvotes: 0

Views: 55

Answers (1)

gareththegeek
gareththegeek

Reputation: 2418

Load the texture in once, then pass a reference to it into the constructor of each grass instance.

Upvotes: 3

Related Questions