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

2014/12/6

GifImage error

1
2
Dalvengyr Dalvengyr

2014/12/6

#
This is my code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Stickman here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Stickman extends Global
{
    private GifImage Img = new GifImage("stickman.gif");
    
    /**
     * Act - do whatever the Stickman wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (!IsJumping)
            setImage(Img.getCurrentImage());
    }   
}
It doesn't play the animation. I'm sure I wrote the filename correctly and it's been properly imported. Then if I try to re-compile or reset, it prints a message: "Constructor of the world is taking a long time...." I need to re-open my greenfoot to compile it. Yet the animation still wasn't played.
davmac davmac

2014/12/6

#
Are you certain the problem is to do with the use of GifImage? If you comment out lines 11, 19 and 20 does the problem go away?
Dalvengyr Dalvengyr

2014/12/6

#
The problem goes away if I don't create Stickman actor (after re-opening the Greenfoot). First time I open Greenfoot it compiles normally, then I tried to add Stickman actor. The animation doesn't play, and the I retry to re-compile but it prints that "Constructor of the world is taking a long time...." :/
danpost danpost

2014/12/6

#
NVM. You did say re-compile, which would exclude what I was saying here.
Dalvengyr Dalvengyr

2014/12/6

#
There is only one class named "Global" with all necessary variable declarations
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Global here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public abstract class Global extends Actor
{
    public static boolean IsJumping = false;
    public static Stickman Runner;
}
Stickman is Global's subclass, I doubt if it's the cause. And there is no other classes (not yet), except imported GifImage class.
danpost danpost

2014/12/6

#
My next thought was checking the Global class. Are the fields being used anywhere at all, atm?
Dalvengyr Dalvengyr

2014/12/6

#
What field? I don't modify those variable anywhere, said I just have two classes atm (Global and Stickman).
danpost danpost

2014/12/6

#
Either one. Ok. You do not modify them; but, do you even reference them at all as yet? Oh, and you must have a third class -- a World subclass.
Dalvengyr Dalvengyr

2014/12/6

#
This is my world declaration:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class White here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class White extends World
{

    /**
     * Constructor for objects of class White.
     * 
     */
    public White()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        Greenfoot.start();
    }
}
So I'm sure I haven't used them anywhere except on that stickman My gif image's dimensions is 150x81. Is that the possible problem?
danpost danpost

2014/12/6

#
Remove line 20. As of late, that has been causing some problems.
Dalvengyr Dalvengyr

2014/12/6

#
danpost wrote...
Remove line 20. As of late, that has been causing some problems.
Nope. Still happens the same :/
danpost danpost

2014/12/6

#
Is that the total extend of your code in this scenario?
Dalvengyr Dalvengyr

2014/12/6

#
Those are all classes in the scenario atm (except GifImage class).
davmac davmac

2014/12/6

#
The problem goes away if I don't create Stickman actor (after re-opening the Greenfoot).
Nevertheless, could you try, as I suggested, commenting out lines 11, 19 and 20?
Dalvengyr Dalvengyr

2014/12/6

#
davmac wrote...
The problem goes away if I don't create Stickman actor (after re-opening the Greenfoot).
Nevertheless, could you try, as I suggested, commenting out lines 11, 19 and 20?
The problem's gone after I commented out those lines.
There are more replies on the next page.
1
2