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

2011/10/29

Little Crab programming

BCC BCC

2011/10/29

#
I have just started using greenfoot and have almost finished the crab scenario. I have a problem though. When the crab changes images, it is way to fast. It says in the book that I should make a method so that it changes pictures slower. Unfortunately I have no clue how to do this. Do any of you know how to?
ez4u2c ez4u2c

2011/10/30

#
Presuming that you are using the multiple images to animate the crab, and presuming you are using the act() method of the crab object to change the crab's image, you could make a counter variable to determine how many iterations of act() occur before each image change, effectively slowing the rate at which the images are cycled. Maybe you only want to animate the crab's image when it is moving, in which case you could put the code within a crab movement method.
BCC BCC

2011/10/30

#
    private void animate()
    {
            if(frameNum == 0)
        {
            setImage(image1);
        }
        else if(frameNum == 20)
        {
            setImage(image2);
        }
        else if(frameNum == 39)
        {
            setImage(image1);
            frameNum = 0;
        }
        frame ++;
    }
}
I got this code, but the last line "frame ++;" is not recognised.
BCC BCC

2011/10/30

#
    private void animate()
    {
            if(frameNum == 0)
        {
            setImage(image1);
        }
        else if(frameNum == 20)
        {
            setImage(image2);
        }
        else if(frameNum == 39)
        {
            setImage(image1);
            frameNum = 0;
        }
        frame ++;
    }
}
I got this code, but the last line "frame ++;" is not recognised.
ez4u2c ez4u2c

2011/10/30

#
So have you declared frameNum or frame as your counter? (you didn't show the declaration)
You need to login to post a reply.