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

2011/7/22

Can I use a mirrorHorizontally with a animation?

The_Mac The_Mac

2011/7/22

#
I have a animation which goes to the left, but it also has to go to the right. Can I use the mirrorHorizontally in GreenfootImage to flip the images and still keep the animation and if yes, who should I do it?
DonaldDuck DonaldDuck

2011/7/23

#
private static GreenfootImage[] frame = new GreenfootImage[number of frames you have multiplied by two and add one]

public myActor()
{
    frame[0] = new GreenfootImage("firstFrame");
    frame[1] = new GreenfootImage("secondFrame");

    frame[2] = new GreenfootImage("firstFrame");
    frame[3] = new GreenfootImage("secondFrame");

    for(int i = 2; i < 3; i++)
    {
        frame[i].mirrorHorizontally();
    }
}
You could also define the images when you make the image array, but this looks more organized. There's other ways to do this, but I think this is the easiest way. All you need to do with your animation for moving right now is use the mirrored frame(s) in your animation code.
The_Mac The_Mac

2011/7/23

#
/** [number of frames you have multiplied by two and add one]*/
    private static GreenfootImage[] frame = new GreenfootImage

    
    public Leatherface()
    {
        frame[0] = new GreenfootImage("leatherface0");  
        frame[1] = new GreenfootImage("leatherface1");  
   
        for(int i = 0; i < 1; i++)  
        {  
            frame[i].mirrorHorizontally();  
        }  
    }
I have tried to use your code, but constantly gets the same error!
'(' or ' It marks the line
public Leatherface()
Were have I made an error?
DonaldDuck DonaldDuck

2011/7/24

#
Two things, in line 2, you will need to add the square brackets and the number 3 after your declaration (private static GreenfootImage frame = new GreenfootImage) and then in lines 7,8, you will need to add the file extention to your image names (like "leatherface0.png") What your doing is making an array of greenfootimages, frame being the first frame in the animation, and frame the second image, both mirrored horizontally. Animate them by alternating between frame 0 and 1.
The_Mac The_Mac

2011/7/24

#
Thanks :)
You need to login to post a reply.