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

2022/1/8

How can I flip the image of an actor when it turns 180 degrees?

Rety Rety

2022/1/8

#
How can I flip the image of an actor when it turns 180 degrees without it getting flipped non stopped?
danpost danpost

2022/1/8

#
Rety wrote...
How can I flip the image of an actor when it turns 180 degrees without it getting flipped non stopped?
By keeping a copy of both images. Kept in an image array:
private GreenfootImage[] images = new GreenfootImage[2];
and assigning their images in the constructor of the class:
public << ClassName >>()
{
    images[0] = getImage();
    images[1] = new GreenfootImage(images[0]);
    images[1].mirrorVertically();
}
this line at end of act method:
setImage(images[((getRotation()+90)%360)/180]);
should do the trick.
Rety Rety

2022/1/8

#
It works! Thank you.
You need to login to post a reply.