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

  • Home
  • SEARCH
  • 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 8099163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:18:52+00:00 2026-06-05T22:18:52+00:00

Programming language: Java Ok, so I want to have a BufferedImage that keeps rotating

  • 0

Programming language: Java

Ok, so I want to have a BufferedImage that keeps rotating infinitely. I’m still pretty new at asking good question, so do bear with me.

I have a BufferedImage called arm and it is rectangular and I have an ActionListener that loops repaint() every 100 milliseconds
my code is:

public void paint(Graphics g){ 
    AffineTransform t = new AffineTransform(); 
    t.rotate(Math.toRadians(90),(a­­rm.getWidth()/2)*scale,0); 
    t.translate(300,300); 
    g.drawImage(arm,t,null);
}

If you’re wondering I resized the image 4x bigger so the variable scale = 4. I think my error is that I’m not mapping the pivot-point correctly but I have no idea. I really need this for my game so please help I am sooooo desperate right now.

  • 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-05T22:18:54+00:00Added an answer on June 5, 2026 at 10:18 pm

    A new AffineTransform always has zero rotation. You are adding a 90-degree rotation, so every frame of your animation will look the same: the image rotated 90 degrees from its normal orientation.

    You need to calculate the current rotation angle.

    // Instance variable intialized at zero.
    double angle = 0.0;
    
    // In your ActionListener timer handler increment the angle.
    {
        angle += Math.toRadians(5); // 5 degrees per 100 ms = 50 degrees/second
        while (angle > 2 * Math.pi()) 
            angle -= 2 * Math.pi();  // keep angle in reasonable range.
    }
    
    public void paint(Graphics g) {
        // Just use the transform that's already in the graphics.
        Graphics2d g2 = (Graphics2d) g;
        g2.setToIdentity();
        // The code for your other transforms is garbled in my browser. Fill in here.
        g2.rotate(angle);
        g2.drawImage(arm, t, null);
    }  
    

    Hope this gets you closer.

    I’ll add that 100 ms is pretty slow for a frame rate. The animation will look jerky. Smooth action needs at most 30 ms or 30 frames per second. Games that use the GPU sometimes run over 100 fps.

    And you should avoid new when possible inside the animation loop. It will require the garbage collector to run more frequently. This can cause a stutter in the animation.

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

Sidebar

Related Questions

I want to learn a new programming language. I have in mind stuff like
I'm new on Java and Android programming language and this is the first platform
I have been programming in Java (my first language) for about six months and
I'm very new to Java programming language so this is probably dumb question but
I want to learn a new programming language and develop for the Android platform.
I am using sqlite and java as programming language. I have a class which
I'm new to Android and the Java programming language but I know what application
My question is about angle functions in programming languge Java. if i want to
I was reading Joshua Bloch's Effective Java Programming Language Guide . He explains static
In any programming language (like php, java, javascript etc) is it possible to dynamically

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.