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

2013/5/26

Animation of Pacman

jaydjay jaydjay

2013/5/26

#
I need help with animating Pacman. It seems as though it is animating too fast, as in moving it's mouth too quickly ( it's like on drugs :D ) What should i do?
private void moving()
    {
        if ( !treeFront() )
        {
            Movement();
        }
if ( Greenfoot.isKeyDown("up") )
         {
             Direction(UP) ;
         }
        if ( Greenfoot.isKeyDown("down") )
        {
            Direction(DOWN) ;
        }
        if ( Greenfoot.isKeyDown("left") )
        {
            Direction(LEFT) ;
        }
        if ( Greenfoot.isKeyDown("right") )
        {
            Direction(RIGHT) ;
        }
void Movement()
    {
        if ( !frontWall() && !ghostWallFront() )
        {
            move(3);
            animate();
        }
    }
Gevater_Tod4711 Gevater_Tod4711

2013/5/26

#
Therefore it would be helpfull to know how your animate method looks like and how it works. Probably this method just changes the image from packman with open mouse to packman with a closed mouse. In this case you should try to use a global variable to count the acts till the next image change:
private int imageCounter = 0;

public void act() {
    //...
    imageCouner++;
    if (imageCounter >= 10) {//If you use a greater value the animation will be slower and faster if you use a smaler value.
        animateImage();
        imageCounter = 0;
    }
}
jaydjay jaydjay

2013/5/27

#
However, im trying to animate it like pacman. It should be animating every step it moves once. Any suggestions?
Gevater_Tod4711 wrote...
Therefore it would be helpfull to know how your animate method looks like and how it works. Probably this method just changes the image from packman with open mouse to packman with a closed mouse. In this case you should try to use a global variable to count the acts till the next image change:
private int imageCounter = 0;

public void act() {
    //...
    imageCouner++;
    if (imageCounter >= 10) {//If you use a greater value the animation will be slower and faster if you use a smaler value.
        animateImage();
        imageCounter = 0;
    }
}
jaydjay jaydjay

2013/5/28

#
anyone?
davmac davmac

2013/5/28

#
Use more images in your animation sequence to get a smoother animation. I.e. mouth closed, mouth only a tiny bit open, mouth slightly more open, mouth half open, etc.
jaydjay jaydjay

2013/5/28

#
I can only use one image though
davmac davmac

2013/5/28

#
That doesn't make sense. You need at least two images for animation - one with the mouth open and one with it shut. If you have only two images and you want to slow the animation, you have two choices: move less often, or do not animate every time you move. (You'll never get it to look like the original pacman this way; you need more images).
You need to login to post a reply.