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

2015/9/15

how do i set a .gif image as a image for a world?

ZoSo ZoSo

2015/9/15

#
i used the GifImage class, made an actor class called background and set a .gif image but whenever i try making the paint order so that the .gif image is in the back of other objects i get an error this is my world class:
import greenfoot.*;

/**
 * Write a description of class InfinitePong here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class InfinitePong extends World
{
    GreenfootSound inf = new GreenfootSound("infinite.wav");
    
    /**
     * Constructor for objects of class InfinitePong.
     * 
     */
    public InfinitePong()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        
        //inf.playLoop();
        
        Counter counter = new Counter();
        addObject(counter, 180, 30);

        Counter counter2 = new Counter();
        addObject(counter2, 666, 30);

        Ball ball = new Ball(counter, counter2);
        addObject(ball, 405, 306);

        Player1 player1 = new Player1();
        addObject(player1, 60, 100);

        Opponent2 op2 = new Opponent2(ball);
        addObject(op2, 748,520 );
        
        Background2 b = new Background2();
        addObject(b, 400, 400 );
        
        setPaintOrder(Ball.class, Background2.class);
    }
    
    public void act()
    {
        if(Greenfoot.isKeyDown("backspace"))
        {
            inf.stop();
            Greenfoot.setWorld(new Title());
            
        }
    }
}
and this is my .gif actor:
import greenfoot.*;

/**
 * Write a description of class Background2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Background2 extends Actor
{
    GifImage myGif = new GifImage("2playerz.gif");
    /**
     * Act - do whatever the Background2 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage(myGif.getCurrentImage());
    }    
}
Super_Hippo Super_Hippo

2015/9/15

#
ZoSo wrote...
i get an error
What is the error message?
ZoSo ZoSo

2015/9/15

#
nvermind i fixed it
You need to login to post a reply.