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

2013/1/11

scoreboard + font style

bonana bonana

2013/1/11

#
Hey,

1

how do I chose the font style of my text when I use:
GreenfootImage bg = getBackground();
        Color c1 = new Color(x, y, z);  
        bg.setColor(c1);        
        Font f1 = new Font(what do I have to place here to chose the font?);  
        bg.setFont(f1);        
        bg.drawString("hello world", x, y);

2

And I've got another problem with my own scoreboard. The scoreboard gets activated by actor z, whose score is not counted. The scoreboard should display the score of actor a, actor b and actor c. I tried to use a public static int scoreA / scoreB / scoreC in the classes of these actors and "actor a" + scoreA / "actor b" + scoreB / "actor c" + scoreC as a string in the scoreboard class, but it always shows a score of 0. Does anyone know how to fix it? (I'm sure you do ;-) )
Gevater_Tod4711 Gevater_Tod4711

2013/1/11

#
In the API of the class Font you can easily read what has to be in the constructor of Font. You probatly need the third one public Font(String name, int style, int size). name is just a name for this font. style is a style number you can get from the fieldsummary (use it like this: Font.BOLD) size is the font-size of your font (how big the letters should be) For your second problem we need to see your code.
bonana bonana

2013/1/11

#
Thanks for answering my first question. But for the second one I just want to know how I could define an integer that is available for every class in my scenario. ;-)
Gevater_Tod4711 Gevater_Tod4711

2013/1/11

#
If you declare an integer as statis you can easily get the value of this integer like this:
public class A {
    public static int staticInteger = 1;//this is the static integer variable; it has to be declared public to use it like in the class B;
    
    //in this class (or better in objects of this class) you can set the value of the static variable like all other variables:
    public void act() {
        staticInteger = 5;
    }
}

public class B {
    //in this class you cant do it like in class A but like this:
    public void act() {
        A.staticInteger = 7;//A has to be the name of the class where the static int is declared and then staticInteger is the name of the variable;
    }
}
bonana bonana

2013/1/12

#
Thanks, the A.staticInteger stuff was what I needed to know ;-)
You need to login to post a reply.