How to draw LibGDX Sprite from Blank Constructor

I am trying to draw Sprite in LibGDX. I can do this if I use a constructor that indicates the texture to use, for example

 Sprite sprite = new Sprite(new Texture(Gdx.files.internal("path"))); 

but if I use Sprite(); instead Sprite(); and try to use setTexture and / or setRegion , the image will not be drawn. The API says that before you can draw, you need to set "texture, texture area, borders, and color." I called setTexture , setRegion and setColor , although nothing is drawn.

The main question is: if I use the default constructor of Sprite() , what should I do after this to make sure that it draws on the screen (in SpriteBatch )?

+4
source share
1 answer

I would suggest that the code should follow the same steps as the ctor sprite (texture) :

 public Sprite (Texture texture) { this(texture, 0, 0, texture.getWidth(), texture.getHeight()); } public Sprite (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); } 

These are all publicly available methods.

+3
source

All Articles