I have a class that looks something like this:
public class MyResources
{
public static final Size textureSize = new Size(72, 96);
public Texture texture;
public TextureRegion textureRegion;
private static BGRResources instance = null;
protected BGRResources()
{
// Protected to prevent direct instantiation.
texture = new Texture(Gdx.files.internal("data/mytex.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
textureRegion = new TextureRegion(texture, 0, 0, 72, 96);
//textureRegion = new TextureRegion(texture, 0, 0, textureSize.width, textureSize.height);
}
public static MyResources getInstance()
{
if (instance == null)
{
instance = new MyResources();
}
return instance;
}
}
Size is a simple class with just public width and height floats.
I want to replace the line where textureRegion is set to the line below it, which is commented out. When I do that, the region no longer works -- I get nothing when it is drawn in an Image. The line above, which to my C programming (i.e. preprocessor) brain should be absolutely identical, works fine.
Why? I tried duplicating the problem in a simpler, non-libGDX class, but couldn't. I thought maybe the static final Size class wasn't actually getting instantiated before it was being used to create the textureRegion, but both the debugger and my attempt at simplifying it seemed to disprove that.
As indicated above, I'm a C guy, where the order of things like this is very clear. It gets muddy for me here, so I could use any education on how to properly declare #define equivalents or singleton classes that might come along with the answer. Thanks.