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

2019/11/25

Setting Images

TylerBlair TylerBlair

2019/11/25

#
I am having trouble getting my image to appear on my background. I have looked through all the docs and believe that I have the code right however the image won't show up but the problem still runs. Any suggestions? Thanks!
public class Start extends World
{
    
    public Start()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1080, 599, 1); 
        GreenfootImage back = getBackground();
        back.setColor(Color.BLACK);
        back.fill();
        Greenfoot.start();
        message();
    }
    public void act()
    {
        if (Greenfoot.isKeyDown("space")) Greenfoot.setWorld(new MyWorld());
    }
    private void message()
    {
        //showText("Directions", 1000, 25);
        GreenfootImage directions = new GreenfootImage("directions.png");
        directions.drawImage(directions, 300, 300);
    }
}
danpost danpost

2019/11/25

#
TylerBlair wrote...
I am having trouble getting my image to appear on my background. I have looked through all the docs and believe that I have the code right however the image won't show up but the problem still runs. Any suggestions? << Code Omitted >>
Your last line draws an image offset onto itself. The background image of the world is not involved in that draw operation.
TylerBlair TylerBlair

2019/11/26

#
danpost wrote...
TylerBlair wrote...
I am having trouble getting my image to appear on my background. I have looked through all the docs and believe that I have the code right however the image won't show up but the problem still runs. Any suggestions? << Code Omitted >>
Your last line draws an image offset onto itself. The background image of the world is not involved in that draw operation.
How should I change it so the image displays on top of the black background?
danpost danpost

2019/11/26

#
TylerBlair wrote...
How should I change it so the image displays on top of the black background?
To display it "on top", you would use an actor. To display it "on", draw the directions image onto the background of the world.
You need to login to post a reply.