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

2019/12/3

setImage doesn't work in World subclass

BkS BkS

2019/12/3

#
Hello everybody, I have been working on a game for college and I'm currently putting the final touches to it. Currently my timer is shown using the showText method, however I want to use a custom font instead. My code for the timer is in the MyWorld subclass, and I'm trying to make the following code work:
GreenfootImage img = new GreenfootImage(500, 100);
img.setColor(Color.BLACK);
img.fill();
img.setColor(Color.RED);
img.setFont(new Font("Calibri", false, false , 100));
img.drawString("Time Left: "+ timer/60 + " sec", 700, 15);
setImage(img);
I note that "setImage()" doesn't work in the MyWorld subclass, so how do I make it work? Thank you.
BkS BkS

2019/12/4

#
Bump
danpost danpost

2019/12/4

#
Actors use setImage and worlds use setBackground. However, I doubt you want this particular image to be tiled on your world's background. You probably should create an actor, give it this image to use and add it into the world. Another option is to use setText on the world; however, then you will not be able to control color, font and size.
You need to login to post a reply.