In Greenfoot, the actor rotates around the centre of it's image. Is there any way to manually designate this point without having to alter the image?
int wide = getImage().getWidth(); int high = getImage().getHeight(); int xOff = wide/2-rotX; int yOff = high/2-rotY; int xDiff = (int)Math.abs(xOff); int yDiff = (int)Math.abs(yOff); GreenfootImage base; base = new GreenfootImage(wide+2*xDiff, high+2*yDiff); base.drawImage(getImage(), xDiff+xOff, yDiff+yOff);
int rotX = getImage().getWidth()/2 + /* x-offset from center of image*/; int rotY = getImage().getHeight()/2 + /* y-offset from center of image */;
import greenfoot.*;
public class TurretGun extends Turret
{
public TurretGun()
{
int wide = getImage().getWidth();
int high = getImage().getHeight();
GreenfootImage base;
base = new GreenfootImage(wide, high+56);
base.drawImage(getImage(), 0, 56);
setImage(base);
}
public void act()
{
if (Greenfoot.isKeyDown("left"))
{
turn(-1);
}
if (Greenfoot.isKeyDown("right"))
{
turn(1);
}
}
}