Classes that represent images, such as AtlasSprite, couldn't be adjusted well with resizing methods such as setScale and setSize. The size can be adjusted with setScale, but of course the image ratio will also change. What should I do if I want to resize the image to a smaller size while keeping the image ratio? What if you want to cut the image well while keeping the scale as it is?
Override the draw method.
Generally speaking, if you do it like this, it will work. It feels like narrowing down the drawing area for each frame in the draw method.
AssetManager manager = new AssetManager();
TextureAtlas atlas = manager.get("hoge",TextureAtlas.class);
TextureAtlas.AtlasSprite sprite = new TextureAtlas.AtlasSprite(atlas.findRegion("hoge")){
@Override
public void draw(Batch batch) {
batch.draw(this, this.getX(), this.getY(), this.getOriginX(), this.getOriginY(),
this.getWidth() /2f, this.getHeight()/2f, //Halve the height and width
this.getScaleX(), this.getScaleY(), this.getRotation());
}
};
How to resize a sprite in Libgdx?
Recommended Posts