Search code examples
javatranslationaffinetransform

Java AffineTransform Translation isn't working


UPDATE Turns out I'm just tired. There isn't any problem here sorry for wasting your time. Don't worry I flagged this for a moderator to look at.

My problem is that when I translate a bufferedimage in java it moves up and down while im translating it on the x axis. For a better understanding of my problem watch this:
http://www.youtube.com/watch?v=stwi1qVakp4

So what is my setup: Well, What i do is in my rendering method I have:

AffineTransform.translate(player_dx,0);

Then I'd have a keylistener that is like:

public void keyPressed(KeyEvent e){
    int key = e.getKeyCode();
    if(key == KeyEvent.VK_RIGHT){
        player_dx = 1;
    }
    if(key == KeyEvent.VK_LEFT){
        player_dx = -1;
    }

}

 public void keyReleased(KeyEvent e){
    int key = e.getKeyCode();
    if(key == KeyEvent.VK_RIGHT){
        player_dx = 0;
    }
    if(key == KeyEvent.VK_LEFT){
        player_dx = 0;
    }

}

I think this is happening because when i rotate it changes the x, y coordinates so if it's 90 degrees the x and y change. I just don't know if I can bypass that.

Just tell me if you need to know anything else. Thanks, Javaman111


Solution

  • Your problem is in the code for the arm, not the affine transform for the character. It probably has to do with how much your moving the arm on each axis or you may have reversed your X and Y by mistake.