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

2016/10/21

Flipping continuously error :(

regwang regwang

2016/10/21

#
I'm trying to create a Mover which will move based on the key controls and make it mirrorVertically when right is clicked for the for if it wasn't facing right originally and when it is going from facing right to any other direction. When I click left, the Mover continuously flips and when I click up after, it still continues flipping.. I checked out other people's discussions but they didn't help much.. I can provide code for this as well
Super_Hippo Super_Hippo

2016/10/21

#
Showing your attempt would probably help.
regwang regwang

2016/10/22

#
i think i was right because I copied the code onto another version and it worked, but another issue is that myActor dims when flipped after this line: getImage().mirrorVertically();
danpost danpost

2016/10/22

#
I tried to locate a method I had previously given in a discussion thread that dealt with this issue; but, I could not find it. It was something like this:
public static GreenfootImage getVerticallyMirroredImage(GreenfootImage image)
{
    GreenfootImage image2 = new GreenfootImage(image);
    image2.clear();
    for (int j=0; j<image.getHeight(); j++)
    {
        for (int i=0; i<image.getWidth(); i++)
        {
            image2.setColorAt(i, image.getHeight()-1-j, image.getColorrAt(i, j));
        }
    }
}
Just give the method the image you want to mirror vertically and it will return that mirrored image without dimming or slight color changing (a long-standing java issue, I believe).
Super_Hippo Super_Hippo

2016/10/22

#
I guess there is a line missing in the end of the method:
return image2;
(And obviously there is an 'r' too much in 'getColorrAt'.)
danpost danpost

2016/10/22

#
Super_Hippo wrote...
I guess there is a line missing in the end of the method:
return image2;
Yeah, I missed that line, which should be placed between lines 11 and 12. Thanks, @Super_Hippo.
Nosson1459 Nosson1459

2016/10/23

#
u probably forgot 2 make it only go once
danpost danpost

2016/10/23

#
Nosson1459 wrote...
u probably forgot 2 make it only go once
I did not think it was necessary after another version was tried -- and it worked.
Nosson1459 Nosson1459

2016/10/23

#
yeah just sayin
You need to login to post a reply.