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

2019/2/20

end of gif

petyritonel petyritonel

2019/2/20

#
is there a way to check if a gif finished the animation? the problem is that the gif is looping, and i want to remove it after it's over.
danpost danpost

2019/2/20

#
Save the first image in a field. Use a boolean field to detect when that image is involved in a changing of images.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// fields
private boolean isFirstImage;
private GreenfootImage firstImage;
private GifImage gif = ...;
 
// in act
setImage(gif.getCurrentImage()); // update image
if (firstImage == null) // initializing (only executed during first act step)
{
    firstImage = getImage(); // retain first image
    isFirstImage = true; // set tracking field
}
if (isFirstImage != (getImage() == firstImage)) // if an image change involved first image
{
    isFirstImage = ! isFirstImage; // toggle tracking field
    if (isFirstImage) getWorld().removeObject(this); // if returning to first image, remove this
}
petyritonel petyritonel

2019/2/20

#
thank you so much! this also helped me understand better the usage of gifs in greenfoot.
You need to login to post a reply.