How to crop an image with libGDX

How to cut Atlas Sprite etc.

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?

Method

Override the draw method.

code

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());
   }
};

Reference URL

How to resize a sprite in Libgdx?

Recommended Posts

How to crop an image with libGDX
How to blur an image (super easy)
How to give your image to someone with docker
[Rails] How to build an environment with Docker
How to make an image partially transparent in Processing
How to create an application
How to push an app developed with Rails to Github
How to make an almost static page with rails
How to output standard from an array with forEach
How to number (number) with html.erb
How to update with activerecord-import
How to handle an instance
Post an image with POSTMAN
[Rails] How to display an image in the view
How to specify db when creating an app with rails
How to make an app using Tensorflow with Android Studio
How to erase test image after running Rspec test with CarrierWave
How to scroll horizontally with ScrollView
How to get started with slim
How to enclose any character with "~"
How to use mssql-tools with alpine
How to insert an external library
How to get along with Rails
How to distinguish ubuntu cloud image
How to start Camunda with Docker
How to make an image posted using css look like an icon
How to adjustTextPosition with iOS Keyboard Extension
How to share files with Docker Toolbox
How to compile Java with VsCode & Ant
[Java] How to compare with equals method
[Android] How to deal with dark themes
How to use BootStrap with Play Framework
[Rails] How to use rails console with docker
How to switch thumbnail images with JavaScript
[Note] How to get started with Rspec
How to publish an application on Heroku
How to do API-based control with cancancan
How to achieve file download with Feign
How to update related models with accepts_nested_attributes_for
How to define an inner class bean
How to set JAVA_HOME with Maven appassembler-maven-plugin
How to implement TextInputLayout with validation function
How to handle sign-in errors with devise
How to delete data with foreign key
How to test private scope with JUnit
How to monitor nginx with docker-compose with datadog
How to implement image posting using rails
How to deal with Precompiling assets failed.
How to write an RSpec controller test
How to achieve file upload with Feign
How to run Blazor (C #) with Docker
How to build Rails 6 environment with Docker
[Java] How to turn a two-dimensional array with an extended for statement
How to convert an array of Strings to an array of objects with the Stream API
[Swift] How to set an image in the background without using UIImageView.
How to make an app with a plugin mechanism [C # and Java]
How to download Oracle JDK 8 rpm with curl
[Java] How to test for null with JUnit
How to mock each case with Mockito 1x
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
Downgrade an existing app created with rails 5.2.4 to 5.1.6