logo
down
shadow

Howto rotate a Sprite after resizing the Sprite with setBounds ? (LIBGDX)


Howto rotate a Sprite after resizing the Sprite with setBounds ? (LIBGDX)

By : alncat
Date : October 25 2020, 09:10 AM
may help you . setCenter(x, y) set the position of the Sprite so it is centered to this position:
code :
/** Sets the position so that the sprite is centered on (x, y) */
public void setCenter(float x, float y){
    ...
}
/** Sets the origin in relation to the sprite's position for scaling and rotation. */
public void setOrigin (float originX, float originY) {
    ...
}


Share : facebook icon twitter icon
libgdx - sprite does not rotate

libgdx - sprite does not rotate


By : Brian
Date : March 29 2020, 07:55 AM
I wish this helpful for you This is the create() Method: , Using
code :
sprite.draw(batch)
batch.draw(sprite,x,y)
Rotate a Sprite around another Sprite -libGDX-

Rotate a Sprite around another Sprite -libGDX-


By : Angel
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I can't test right now but I think the rotation of the line should simply be:
Math.atan2(rotatedPoint.getOriginX() - middlePoint.getOriginX(), rotatedPoint.getOriginY() - middlePoint.getOriginY()));
How to rotate a sprite around the origin of another sprite in LibGDX?

How to rotate a sprite around the origin of another sprite in LibGDX?


By : fau patrick
Date : March 29 2020, 07:55 AM
seems to work fine You have the center of your sprite and the another sprite. You can calculate the distance between them. Once you have it and the angle of the rotation, you rotate your sprite and you calculate the position of the another sprite. If its in the right position you rotate the another sprite by the negative value of your angle.
cannot rotate my sprite in libgdx

cannot rotate my sprite in libgdx


By : user7107095
Date : March 29 2020, 07:55 AM
I wish this helpful for you Sprite holds the geometry, color, and texture information for drawing 2D sprite. In geometry, it carry sprite position, size, rotation and scale.
By using below method you're only passing position and size of player Sprite.
code :
game.batch.draw(atlas2.findRegion("player"), player.getPosition().x, player.getPosition().y, player.PLAYER_DIMENSION , player.PLAYER_DIMENSION);
TextureAtlas atlas2=....;
Sprite player=new Sprite(atlas2.findRegion("player"));
public class Player extends Sprite {

   public Player(TextureRegion region){    // <- Add this constructor 
       super(region);
       ...
   }
}
Player player=new Player(atlas2.findRegion("player");
LibGDX: Sprite.setBounds doesn't work correctly with volatile coordinates and InputAdapter

LibGDX: Sprite.setBounds doesn't work correctly with volatile coordinates and InputAdapter


By : tizianhuber
Date : March 29 2020, 07:55 AM
help you fix your problem So, I sequentially compared the XY coordinates of the image and the mouse click point and came to the conclusion that InputAdaper and Sprite consider Y differently - from above and from below. Therefore, X always coincided, and Y had a big difference in values.
As a result, I entered two corrected coordinates xPos \ yPos (Y subtracted from the total field height) for the center of the pic and in the touchDown() method, instead of comparing with BoundRectangle, simply compared the difference in the coordinates of the pic and the click modulo. If the result into the image size range - everything is ok.
code :
   public void render(SpriteBatch batch, float radius, float boost) {
    speed+=boost; // rotational speed
    nextX = radius * (float) Math.cos(speed); // Offset step X
    nextY = radius * (float) Math.sin(speed); // Offset step Y

    // set image size and position
    img.setBounds(startPosition.x+nextX, startPosition.y+nextY, 100, 100);
    img.draw(batch);

    // Corrected coordinates of the image for InputAdapter coordinate system
    xPos = img.getX()+img.getWidth()/2;
    yPos = Gdx.graphics.getHeight()-img.getY()- img.getHeight()/2;

    // Check the coincidence of the coordinates of the image area and the click point
    Gdx.input.setInputProcessor(new InputAdapter(){
        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if((Math.abs(xPos-screenX)<=img.getWidth()) && (Math.abs(yPos-screenY)<=img.getHeight()))
            {System.out.println("Image Clicked");}
            return true;
        }
    });
}
Related Posts Related Posts :
  • Integration Testing with Kitchen CI
  • Can't seem to get the from <asp:Literal </asp:Literal> property in Web forms
  • Can't access faraday params on views
  • RQM testNG integration
  • How can I enable unit templates?
  • Displaying multiple colors on a single data bar
  • Loading aggregates on reacting to domain events
  • Integrating Azure Cognitive services with Robotic Process Automation
  • Autodesk Forge Design Automation quota
  • Why can i not login to the wso2 api store using the email address of a secondary user store account
  • order not working with sortWhitelist
  • config.site for vendor libs on Fedora x86_64
  • Getting a limit response from Loopback, when no authentication is provided
  • What is the effect of FeedOptions.EnableLowPrecisionOrderBy Property
  • Recordset Null Value not being detected in null check
  • How to connect to an arbitary database using FaaS?
  • SourceTree not working after Windows 10 Fall Creators Update
  • How to get all registered user from Openfire through http
  • Error "invalid parameter" when launching a converted app
  • Using react-sortable-hoc with react-virtualized Grid
  • Xamarin.Forms: How to set values in Style only on specific platform
  • ZSH avoid adding empty commands to history?
  • Grep regular expression - Pattern issue
  • Unable to connect via Java to a DSE graph
  • Check if attachment is up to date with current document revision in couchdb
  • Can I bind an argument value ahead of time when using redux-actions?
  • How to change a member field with Kotlin reflection?
  • Replaying merged streams individually
  • DevExpress GridColumn strange proportional sizing
  • Drools Decision table error : Error while creating KieBase
  • Kafka-Flink-Stream processing: Is there a way to reload input files into the variables being used in a streaming process
  • How to export and import nifi flow from one HDP to another HDP
  • map pointWidth to a single Datapoint in Column Chart
  • Pygame animating image by transforming it
  • Why is my Gdk/cairo class causing a segfault?
  • How to organize queues in Masstransit/RabbitMQ?
  • How to remove a collection element without EntityManager#remove(...) in Doctrine 2?
  • how to change the format of the return value of 'mnist.load_data()' to 'mnist_train.csv' in Keras?
  • CodeFights Interview Practice- Dynamic Programing : Basic : fillingBlocks
  • Accessing the built request details in Karate
  • How to draw a polyline with initial point in Leaflet
  • docusign transform pdf field with text tab as required
  • How to avoid "unused variable in a for loop" error
  • Clipping a polygon to only draw within a circle in Love2D
  • Can't import library in Python
  • Silverstripe - Turn modules on or off in config
  • How does shared memory work behind the scene in Linux?
  • Vue - how to bind table column to a data object?
  • OrientDB deep traversal until specific class
  • Static code analysis of Dockerfiles?
  • Is Batmobile Defy Mini a fake device?
  • Reverse a list to a range
  • Add multiple y-axis to SAPUI5 VizFrame Column Charts
  • Nightmare with rabbitmq.client versions
  • How to change timeout for a request in okhttp
  • How to support relative date parameters in Web Intelligence Report
  • cfEngine3 - class if package is installed
  • Count number of sentences in a string in SAS
  • Visit Last Loaded URL
  • What are the use cases to substitute cookbook array attribute in chef?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org