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

2017/6/8

"If" loops

FeVo FeVo

2017/6/8

#
Hey y'all, First of all Sorry for my bad English ^^ I want that a picture is shown if a condition is met. I already got:
if ( onSchiri() ) {
    
}
and between the "{}" should the code for the picture be written. The picture should have a blue background on which in black is the following sentence standing: "The blue boxer won, because the red boxer ran into the reffere". The picture should fill the whole "world" if u know what I mean. Thanks in front :D
Super_Hippo Super_Hippo

2017/6/8

#
Should it replace the world's background? Since there aren't 'if loops', what do you mean with it? Why do you need a loop?
FeVo FeVo

2017/6/8

#
My English isnt well, just a mistake I realized now after u told me xD Yeah it should replace the background so I can see only the "Picture" Thanks in front ^^
Super_Hippo Super_Hippo

2017/6/8

#
You can try this. Not tested, but it should be close at least.
World w = getWorld();
w.removeObjects(w.getObjects(null)); //remove everything
GreenfootImage img = new GreenfootImage(w.getWidth(), w.getHeight());
img.setColor(Color.BLUE);
img.fill();
img.setColor(Color.BLACK);
//maybe need to adjust font -- for example size
img.drawString("The blue boxer won because the red boxer ran into the referee", w.getWidth()/4, w.getHeight()/2);
//you can create a line break (Zeilenumbruch) with \n if needed
w.setBackground(img);
FeVo FeVo

2017/6/8

#
it looks like this :/
Super_Hippo Super_Hippo

2017/6/8

#
You need to provide the link to the image instead of a link to the website where the image is on: Could it be that your cellsize is more than 1? Change line 3 to that then:
GreenfootImage img = new GreenfootImage(w.getWidth()*w.getCellsize(), w.getHeight()*w.getCellSize());
danpost danpost

2017/6/8

#
And change line 8 to:
img.drawString("The blue boxer won because the red boxer ran into the referee", img.getWidth()/4, img.getHeight()/2);
FeVo FeVo

2017/6/9

#
Thank you two, now it works perfect! EDIT: but how can I change the Font and the size of the written text?
Yehuda Yehuda

2017/6/9

#
FeVo wrote...
but how can I change the Font and the size of the written text?
With the setFont method.
//with the java.awt.Font (version 3.0.4 and earlier)
img.setFont(new Font("Arial", Font.PLAIN, 18)); // fontName, style, size

//with greenfoot.Font (version 3.1.0)
img.setFont(new Font("Arial", false, false, 18)); //fontName, bold, italic, size
FeVo FeVo

2017/6/9

#
Thanks @Yehuda
You need to login to post a reply.