This site requires JavaScript, please enable it in your browser!
Greenfoot back
rachpaguia@gmail.com
rachpaguia@gmail.com wrote ...

2017/3/17

BACKGROOUND

hello!!! so i'm planning to set a background, but the moment i press run, it changes. does anyone know how to do this? thank you so much
danpost danpost

2017/3/17

#
rachpaguia@gmail.com wrote...
hello!!! so i'm planning to set a background, but the moment i press run, it changes. does anyone know how to do this? thank you so much
You will need to give a bit more detail as to what images you want as the background and when -- plus the codes that deal with the background image.
Um because i am making a game, so before making the program run, i want to have a background that says "press run to play" once run is pressed however, the background will change into a new one which is the background that is set when the game is played i hope this is clear enough :(
danpost danpost

2017/3/17

#
Make use of the 'started' method:
public void started()
{
    setBackground(<< new background filename >>);
}
You did not show your code here -- but remove any other places where you try to set that particular image.
public class bg extends World
{
    //GreenfootSound backgroundMusic = new GreenfootSound("music.mp3");
public void started()
{
    setBackground("start.png");
    GreenfootImage bg = new GreenfootImage("start.png");
    bg.scale(getWidth(), getHeight());
}
    public bg()
    {//this sets the background     
super(600, 400, 1);
setBackground("Final ICT BG.png");
//backgroundMusic.playLoop();
        
GreenfootImage bg = new GreenfootImage("Final ICT BG.png");
bg.scale(getWidth() +35, getHeight() +30);
setBackground(bg);
prepare();
//if("enter".equals(Greenfoot.getKey()));
}
Here is my code!! The bg doesn't set properly despite having the bg.scale, and it doesnt change huhu
danpost danpost

2017/3/17

#
I think this is what you want:
public class bg extends World
{
    public bg()
    {
        super(600, 400, 1);
        GreenfootImage bg = new GreenfootImage("Final ICT BG.png");
        bg.scale(600, 400);
        setBackground(bg);
        prepare();
    }
    
    public void started()
    {
        GreenfootImage bg = new GreenfootImage("start.png");
        bg.scale(600, 400);
        setBackground(bg);
    }

    //...
Super_Hippo Super_Hippo

2017/3/17

#
Remove line 7 and change the 'bg' in line 8 to 'getBackground()'. As it is right now, 'bg' is a new image and you scale it, but it is not the same image as the one you set as the background in line 6. Same goes for line 13 vs. line 16. Since you use line 18 there, this 'bg' is used as the background, you can remove line 13 or do the same as described above.
Thank you so much, to the both of you! it's working! i'm sorry i've been asking so much questions for the past days
Nosson1459 Nosson1459

2017/3/17

#
don't be sorry the forum is here for a reason
You need to login to post a reply.