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

2015/3/4

How to bring text image to the front

Twentyonestreet Twentyonestreet

2015/3/4

#
I have an object Timer and I need to put text image on it. I create and update this image in Timer class. But every time this text image goes behind the actor. How to bring text image to the front?
fejfo fejfo

2015/3/4

#
u need to add it to world last if that isn't possible u can try remvoving it and readding it in every act like this
1
2
3
4
5
6
7
8
9
10
11
public void act() {
   World w = getWorld();
   int x = getX();
   int y = getY();
   //only if it rotates
   int r = getRotation();
   w.removeObject(this);
   w.addObject(this,x,y);
  //only if it rotates
  setRotation(r);
}
Super_Hippo Super_Hippo

2015/3/4

#
If Timer and Text are two different classes (which I guess), then you can put this in the constructor of your world:
1
setPaintOrder(Text.class, Timer.class);
If not, I don't see your problem. Maybe you could show your code of how you update the image.
Twentyonestreet Twentyonestreet

2015/3/4

#
Text is not a separate class, it is added in the class timer and updated in act() each time.
1
GreenfootImage timerImage = new GreenfootImage(timer, 25,  Color.BLACK, Color.WHITE);
1
getWorld().getBackground().drawImage(timerImage, timerObject.getX(), timerObject.getY());
timerImage - is a String variable timerObject - is an object of class timer. I thought if text image is updated in act, then it will go above Timer object. But no.
Super_Hippo Super_Hippo

2015/3/4

#
You draw it on the background. The background will never be in front of any actor. Instead, you probably should draw the text on the image of the Timer. Btw, 'timerImage' is not a String variable, it is a GreenfootImage.
danpost danpost

2015/3/4

#
I think you should try using the 'setPaintOrder' statement Super_Hippo suggested; just remove 'Text.class, ' from it.
Twentyonestreet Twentyonestreet

2015/3/4

#
Super_Hippo, thank you!
You need to login to post a reply.