The trick is to rotate the graphics context first, then draw your animation.
Code:
package fg;
import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
public class Test extends BasicGame {
private Animation animation;
private float rotation = 0.0f;
float x = 100.0f;
float y = 200.0f;
public static void main(String args[]) {
Test test = new Test("Test");
try {
AppGameContainer app = new AppGameContainer(test);
app.setDisplayMode(640, 480, false);
app.start();
} catch (SlickException e) {
e.printStackTrace();
}
}
public Test(String title) {
super(title);
}
@Override
public void init(GameContainer container) throws SlickException {
Image[] images = new Image[3];
images[0] = new Image("images/0.png");
images[1] = new Image("images/1.png");
images[2] = new Image("images/2.png");
animation = new Animation(images, 200);
}
@Override
public void update(GameContainer container, int delta) throws SlickException {
rotation += .2f * delta;
}
public void render(GameContainer container, Graphics g) throws SlickException {
//store the current state of transform for later
g.pushTransform();
//rotate the display around the center of the animation
g.rotate(x + animation.getWidth() / 2, y + animation.getHeight() / 2, rotation);
animation.draw(x, y);
//undo rotation so further drawing is not rotated
g.popTransform();
g.drawString("howdy!", 50.0f, 50.0f);
}
}
This code would need to be refined based on how you are managing your animations/entities of course. Comment out the popTransform() line to illustrate what happens when you forget to undo the rotation applied to the graphics context.