Hey all,
I am working on a new game and I have decided to try my hand at rotation. After looking at a few tutorials and learning, I came up with this:
AnimatedSprite.java - handles the actual animation,rotation and movement of sprite
http://pastebin.java-gaming.org/827c3257f21
Entity.java - just a class that handles the default attributes that all sprites will share
http://pastebin.java-gaming.org/27c353f7123
And finally MainFrame.java which just tests our code
http://pastebin.java-gaming.org/7c35f417320
The problem lies in my transform() method of AnimatedSprite.java
public void transform() {
at.setToIdentity();
//translate to center of component
at.translate(this.getX() + getImageWidth() / 2,
this.getY() + getImageHeight() / 2);
//do rotation
at.rotate(Math.toRadians(getFaceAngle()));
//translate so the rotation occurs around the center of the object
at.translate(-getImageWidth() / 2, -getImageHeight() / 2); //is something going wrong here?
}
When I rotate the image, it rotates but it doesn’t seem to rotate around the center of the image as can be seen in the screenshot below:
http://s17.postimage.org/z89wetfjf/rotationproblemscaled.jpg
Any help is appreciated but I will keep working on this. Thanks!