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

2020/3/12

Font of text

pavolbiacko2002 pavolbiacko2002

2020/3/12

#
There is a method showText("text",x,y) but it still writes the same white text that is boring. How can I change it? For example I want Arial, bold, yellow...or I dont know...
danpost danpost

2020/3/12

#
You cannot change the font/size/color of what is displayed by showText (as far as I know). You can however create GreenfootImage objects and setFont and drawString on them.
pavolbiacko2002 pavolbiacko2002

2020/3/14

#
Ok thanks :D
pavolbiacko2002 pavolbiacko2002

2020/3/14

#
@danpost alson can i ask, if method isTouching can be aplied in one Class but with diferrents syntax. I mean I always use it like this: "this.isTouching(SomeName.class), but can be used in one class that I wont include this but I will ask about two objects touching each other? Something like (SomeName1.class).isTouching(SomeName2.class)? Is this possible in some way? If it is can you show me syntax please?
danpost danpost

2020/3/14

#
You cannot use isTouching outside of the class of the one that touches the other as the access modifier on the method is protected. However, there is still a way to acquire the required information in the outer class. Add the following method into the class that is to touch another:
1
2
3
4
public boolean checkTouching(Class clss)
{
    return isTouching(clss);
}
Now, for any object of SomName1 type, the outer class can determine if it is touching a SomeName2 object by calling this method on the SomeName1 object. It appears you want to checks if ANY object of the one class touches an object of the second. That would look something like the following in the outer class:
1
2
3
4
5
6
7
8
9
private boolean is1touching2()
{
    boolean areTouching = false;
    for (Object obj : getWorld().getObjects(SomeName1.class)
    {
        areTouching = areTouching || ((SomeName1)obj).checkTouching(SomeName2.class);
    }
    return areTouching;
}
pavolbiacko2002 pavolbiacko2002

2020/3/14

#
Thank you very much! ;)
You need to login to post a reply.