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?


1 2 3 4 5 6 7 8 9 | 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); |
1 2 | int rotX = getImage().getWidth()/ 2 + /* x-offset from center of image*/ ; int rotY = getImage().getHeight()/ 2 + /* y-offset from center of image */ ; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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 ); } } } |