i have class looks 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 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 simple class public width , height floats.
i want replace line textureregion set line below it, commented out. when that, region no longer works -- nothing when drawn in image. line above, c programming (i.e. preprocessor) brain should absolutely identical, works fine.
why? tried duplicating problem in simpler, non-libgdx class, couldn't. thought maybe static final size class wasn't getting instantiated before being used create textureregion, both debugger , attempt @ simplifying seemed disprove that.
as indicated above, i'm c guy, order of things clear. gets muddy me here, use education on how declare #define equivalents or singleton classes might come along answer. thanks.
you mention size class has 2 float fields width , height. when instantiate textureregion size class, because of method overloading calls separate constructor when pass in integer constants. separate constructor expects uv coordinates normalized range 0 - 1.0. check textureregion api , textures section of open.gl more details.
the easiest fix use case use ints instead of floats in size class.
Comments
Post a Comment