Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8777649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:19:32+00:00 2026-06-13T19:19:32+00:00

I am developing a game for Android using LibGDX. I have to objects in

  • 0

I am developing a game for Android using LibGDX. I have to objects in the game that need to be rotated. The objects are a board, and a tube. The problem that I am having is this, the tube piece consists of three pieces, the center piece, and the end pieces. The tube and the board can be stretched. Because they can be stretched the end pieces have to be separate graphics so that they do not become distorted from being stretched. I am having a really hard time figuring out how to do this properly. The position and rotation are retrieved from a Box2D body.

This is what the object looks like once constructed:

tube piece with end caps http://weaverhastings.com/tube.png

This is the end piece:

end cap for the tube http://weaverhastings.com/tube_endpiece.png

This is the piece that goes in the middle:

middle piece for the tube http://weaverhastings.com/tube_middle.png

From looking at it, it looks like the problem is the origin. As the object is stretched out, the origin for the rotation of the end pieces needs to change. But I cannot figure out how to calculate that origin correctly.

Here is the code that I am using right now:

// Right border
batch.draw(border,                     // AtlasRegion for the border
           position.x,                 // The position as reported from box2d body
           position.y,                 
           25 + 150 * scale.x,         //  25 is 2 x the end piece width, 150 is the width of the middle piece, it is multiplied by the scale because it can be stretched.
           height/2,                   // This is just the height of the tube piece
           border.getRegionWidth(),    // the is the width of the border
           height,                     
           0.6f,                       // The scale of the borders is fixed
           0.8f,                                    
           rotation * MathUtils.radiansToDegrees); // the rotation as retrieved from box2d body

// Left border  
batch.draw(border,
           position.x,
           position.y,
           25 - 150 * scale.x,
           height/2,
           border.getRegionWidth(),
           height,
           0.6f,
           0.8f,
           rotation * MathUtils.radiansToDegrees);

A video can be seen of the tube piece rotating here: http://youtu.be/RusL4Mnitds

Any help would be greatly appreciated. Thank you for reading this far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:19:34+00:00Added an answer on June 13, 2026 at 7:19 pm

    In Libgdx the origin of rotation is relative to the objects position, eg, where you tell it to be drawn.

    So for the left border you would need to say the originX would be half the width of the center piece (middlePiece.width/2) or whatever and for the right piece the originX would need to be negative this value(-middlePiece.width/2). Their positions of course would need to be at the ends of the centre piece when not rotated. The OriginY for each of them would be half the height of the Center piece. (middlePiece.height/2)

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a crime themed android game that will have a high maturity rating
I'm currently developing a game for Android using OpenGL ES 2.0. I have almost
I'm currently developing my first game app for android OS using Processing. I need
I'm developing a game for Android using andEngine. I have to change sprite images
I'm developing an Android game using Canvas element. I have many graphic elements (sprites)
I'm in the process of developing an android game. I have an activity that
I am developing an android game. in this i have two moving images on
I'm developing a game using libgdx in android. I dispose all the textures I
I am developing a new game for Android. In this I am using Android
I'm developing a 2d Game using Canvas/Surfaceview and have a problem with thread. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.