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

2013/10/24

Background

ddvink ddvink

2013/10/24

#
Can someone explain why my background has been drawn a couple of times this way?
    public LevelOne()
    {    
        background = new GreenfootImage("landscape.png");        
        setBackground(background);
       
        getBackground().drawImage(background, 100, 100);
    }
(This is a subclass of class X. Class X is the subclass of World). What I hoped for, is that the background just moved 100 down and 100 to the right. Yours, Dennis
Zamoht Zamoht

2013/10/24

#
setBackground(background); sets the whole background to the given image so it will fill the whole world out even if the image used is to small to fit. Write this instead: background = new GreenfootImage(getWidth(), getHeight()); background.drawImage(new GreenfootImage("landscape.png"), 100, 100); setBackground(background); You may want to add: background.setColor(the color you want); background.fillRect(0, 0, getWidth(), getHeight()); Right after background = new GreenfootImage(getWidth(), getHeight()); If the background color is not what you want.
You need to login to post a reply.