Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

An example image

As you can see above, I have an image of a game I've been working on using Java. Using AWT I added the following:

public static void drawImageRotated(
        Graphics2D g2d, BufferedImage img, double x, double y, int scale, double angle) {

    BufferedImage image = new BufferedImage(
                                     (int)(img.getWidth() * 1.5D),
                                     (int)(img.getHeight() * 1.5D),
    Graphics2D g = (Graphics2D)image.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.rotate(Math.toRadians(angle), image.getWidth() / 2, image.getHeight() / 2);
                image.getWidth()  / 2 - img.getWidth() / 2,
                image.getHeight() / 2 - image.getHeight() / 2,

This is the code which draws the ships onto the screen. As you can see there is a blue and a cyan ship on the screen, the blue ship's rotation being 0 and the cyan having a rotation of just over 270 degrees. The cyan ship is distorted and that's what I want to get rid of. Is there an anti-aliasing for small images like that one (16x16)?

share|improve this question
This is a 16x16 image rotated at a non-right angle; what output are you expecting? – mmyers Feb 1 '13 at 16:46
After reformatting the code, it appears there is an error in the g.drawImage call. Shouldn't the y position be image.getHeight()/2 - img.getHeight()/2? – mmyers Feb 1 '13 at 17:00
So I'm assuming I need to make the image slightly larger. – Alan Tuning Feb 1 '13 at 17:19

That code seems more complicated than necessary, what you need is to just draw your image with the right transformation matrix.

I don't speak Java so there may be mistakes in this, but it should look something like:

AffineTransform transform = new AffineTransform();

The first 4 lines build a translation matrix, you don't need to worry much about how that works, except that the construction order matters.

share|improve this answer
For the record, this should also produce a different visual result. – aaaaaaaaaaaa Feb 2 '13 at 15:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.