This site requires JavaScript, please enable it in your browser!
Greenfoot back
Reny
Reny wrote ...

2016/5/8

Actor is facing the wrong way

Reny Reny

2016/5/8

#
So I have a picture of a plane and it is facing up(north), I am trying to make it move to where ever the plane's nose is facing. But with the code " if(Greenfoot.isKeyDown("up")==true) { move(5); } " the plane is moving side way right. move() moves the actor to where ever the actor is facing, so the plane must be facing right but the How do I change the direction the actor is facing?
danpost danpost

2016/5/9

#
You could use a graphics editor that supports transparencies or you can programmatically rotate the image to face the right direction:
GreenfootImage image = getImage(); // the original
int size = (int)Math.max(image.getWidth(), image.getHeight()); // the longer dimension
GreenfootImage helper = new GreenfootImage(size, size); // the helper image
helper.drawImage(image, (size-image.getWidth())/2, (size-image.getHeight())/2); // helper image with original drawn on it
helper.rotate(90); // rotated image
GreenfootImage finalImage = new GreenfootImage(image.getHeight(), image.getWidth()); // blank image with original dimensions reversed
finalImage.drawImage(helper, (image.getHeight()-size)/2, (image.getWidth()-size)/2); // final image with rotated original drawn on it
setImage(finalImage);
I think I did that correctly. You can use this in the constructor of the class of the plane.
You need to login to post a reply.