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

2017/12/6

Play gif only once?

Recorsi Recorsi

2017/12/6

#
Hello, two months ago i asked how i play gifs only once(or for a certain time) Link to the first question i tried the code i got from danpost:
import greenfoot.*;
  
public class explosion extends Actor
{
    GifImage explosion = new GifImage("explosion.gif");
    GreenfootImage imageOne;
    boolean notImageOne;
     
    public explosion()
    {
        List<GreenfootImage> images = explosion.getImages(); // get list of images
        imageOne = images.get(0); // get reference to first image
        for (GreenfootImage img : images) img.scale(75, 75); // scale all images
        setImage(explosion.getCurrentImage()); // set initial image
    }
 
    public void act() 
    {
        setImage(explosion.getCurrentImage()); // animate
        if ((getImage() != imageOne) != notImageOne) // was there a change involving first image
        {
            notImageOne = ! notImageOne; // record change
            if (! notImageOne) getWorld().removeObject(this); // if setting first image, remove explosion from world
        }
    }
}
But in line 11 i get an error saying that the class "List" wasn't found. how do i fix that issue? i think im doing something wrong. thx :)
danpost danpost

2017/12/6

#
Just add the following import line to the class:
import java.util.List;
Recorsi Recorsi

4 days ago

#
It works, thank you very much :)
You need to login to post a reply.