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

2024/4/23

GifImage Unkown type: GifImage

thijmenvd thijmenvd

2024/4/23

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Draak here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Draak extends Actor
{
    GifImage myGif = new GifImage("draak 11.gif");
    public Draak() 
    {
        
    } 
    /**
     * Act - do whatever the Draak wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        if (Greenfoot.isKeyDown("d")) 
        { 
            move(2); 
        } // Add your action code here.
    }
}
Hello, I had some trouble with importing a gif for an object, I saw some videos about this where they impoted a new class, named GifImage. On my version of greenfoot I cant import this. Is there a way to fix this error? The image of the object is now the image of the gif but its not moving.
danpost danpost

2024/4/23

#
thijmenvd wrote...
<< Code Omitted >> Hello, I had some trouble with importing a gif for an object, I saw some videos about this where they impoted a new class, named GifImage. On my version of greenfoot I cant import this. Is there a way to fix this error? The image of the object is now the image of the gif but its not moving.
I do not see anywhere where you invoke a change in its image. That is, the following is not found anywhere in your code:
setImage(myGif.getCurrentImage());
This should be in the act method somewhere.
thijmenvd thijmenvd

2024/4/23

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Draak here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Draak extends Actor
{
    public Draak() 
    {
        ProcessBuilder.Redirect.Type myGif= new GifImage("draak 11.gif");
    } 
    /**
     * Act - do whatever the Draak wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        if (Greenfoot.isKeyDown("d")) 
        { 
            move(3); 
        } // Add your action code here.
        if (Greenfoot.isKeyDown("a")) 
        { 
            move(-3); 
        } 
        if (Greenfoot.isKeyDown("space")) 
        {     
            setLocation(getX(), getY()-2); 
            move(3); 
        } 
        if (Greenfoot.isKeyDown("s")) 
        { 
            setLocation(getX(), getY()+2); 
        } 
        
        if (getX() >= getWorld().getWidth() - 1) { 
            Greenfoot.setWorld(new Level2());
        }
        setImage(myGif.getCurrentImage()); 
}
} 
My greenfoot wont recognise type: GifImage, and it says Undeclared variable, I changed something in the code. Im new to this program whats the issue in this code?
danpost danpost

2024/4/24

#
thijmenvd wrote...
<< Code Omitted >> My greenfoot wont recognise type: GifImage, and it says Undeclared variable, I changed something in the code. Im new to this program whats the issue in this code?
Replace lines 11 thru 14 with the following:
GifImage myGif;

public Draak() {
    myGif = new GifImage("draak 11.gif");
}
You need to have the GifImage class added to your scenario. If you have to, create any type class and replace all its code with the contents of the following file: greenfoot > lib > greenfoot > common > GifImage.java
You need to login to post a reply.