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

2012/5/31

Actor- changing between two images

Benedict Benedict

2012/5/31

#
i know how to change the image but i dont know how to make it that image 1 is there for a second then image 2 for a second and then image 1 again with other words i want the actor changing the image with a break of a second Any help would be great :)
danpost danpost

2012/6/1

#
You will need a variable to count act frames (chgImgIn). Also, it would be easiest to have the image names in a string array (images), and an int variable to track which image is currently displayed (imgNum). When the counter reaches zero, we change the image number, set the new image, and reset the counter.
static final int CHG_RATE = 10; // adjust to suit
int chgImgIn = 1; 
int imgNum = 1;
String[] images = { "image0.png", "image1.png" };

public void act()
{
    chgImgIn--;
    if (chgImgIn == 0)
    {
        chgImgIn = CHG_RATE; // reset countdown
        imgNum = (imgNum + 1) % 2; // this will alternate {0, 1, 0, 1...}
        setImage(images[imgNum]);
    }
}
Benedict Benedict

2012/6/1

#
thx this helped :)
You need to login to post a reply.