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 8502287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:26:34+00:00 2026-06-11T01:26:34+00:00

Alright guys i’m trying to make an Asteroids type game and I need to

  • 0

Alright guys i’m trying to make an Asteroids type game and I need to be able to rotate an image around so that the front of the ship follows my mouse. I have looked for a few hours now and have found a couple of things but none that satisfy my needs.

If anyone knows how to do this please share!

thanks in advance

here is the code i have now

package Asteroids;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

    import javax.swing.ImageIcon;
    import javax.swing.JFrame;

    @SuppressWarnings("serial")
    public class Asteroids extends JFrame implements Runnable, MouseListener,
            MouseMotionListener, KeyListener {

        private Image dbImage;
        private Graphics dbg;
        int x, y, mx, my;
        int a, b, c, degree;
        double scale = 1.0;
        ImageIcon shipIcon = new ImageIcon(this.getClass().getClassLoader()
                .getResource("AstroidsShip.png"));
        Image ship = shipIcon.getImage();

        public static void main(String[] args) {
            Asteroids frame = new Asteroids();
            Thread thread = new Thread(frame);
            thread.start();
        }

        public Asteroids() {
            addMouseListener(this);
            addMouseMotionListener(this);
            addKeyListener(this);

            setTitle("Astroids");
            setSize(500, 500);
            setBackground(Color.WHITE);
            setResizable(false);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);

            x = getWidth() / 2 - 10;
            y = getHeight() - getHeight() / 2;
        }

        public void run() {
            while (true) {
                try {

                } catch (Exception e) {

                }
            }
        }

        public void paint(Graphics g) {
            dbImage = createImage(getWidth(), getHeight());
            dbg = dbImage.getGraphics();
            paintComponent(dbg);
            g.drawImage(dbImage, 0, 0, this);
        }

        public void paintComponent(Graphics g) {
            g.drawString("POS: " + mx + ", " + my, 10, 40);
            System.out.println(getAngle());
            g.drawImage(ship, x, y, this);
            g.drawLine(x + 12, y + 10, mx, my);
            repaint();
        }

        public int getAngle() {
            a = mx - (x + 12);
            b = (y - 10) - my;
            return degree = (int) Math.toDegrees(Math.atan2(b, a));
        }

        @Override
        public void keyTyped(KeyEvent e) {

        }

        @Override
        public void keyPressed(KeyEvent e) {

        }

        @Override
        public void keyReleased(KeyEvent e) {

        }

        @Override
        public void mouseDragged(MouseEvent e) {

        }

        @Override
        public void mouseMoved(MouseEvent e) {
            mx = e.getX();
            my = e.getY();
        }

        @Override
        public void mouseClicked(MouseEvent e) {

        }

        @Override
        public void mousePressed(MouseEvent e) {

        }

        @Override
        public void mouseReleased(MouseEvent e) {

        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseExited(MouseEvent e) {

        }
    }
  • 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-11T01:26:35+00:00Added an answer on June 11, 2026 at 1:26 am

    You can use Java2D. It allows to rotate the image and do a lot lot of other cool operations on the image. It also have got hardware acceleration support (through DirectX or OpenGL).

    Java2D is built-in in JRE.

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

Sidebar

Related Questions

Alright so i need to open a .txt file that will be created in
Alright guys, Need some help! Im working with asp.net mvc3 razor (and am fairly
I'm trying to make a logo image, which should work as a hyperlink and
Alright, I'm trying to read a comma delimited file and then put that into
Alright, I am trying to accomplish this: When a user clicks a button that
Alright guys, I really hurt my brain over this one and I'm curious if
Alright so I have been looking around (on SO and Google) to see if
Alright, here I am again trying to write code from scratch and I can't
Alright guys, I have looked on the internet for ages and simply could not
Alright, an easy one for you guys. We are using ActiveReport's RichTextBox to display

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.