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

2020/12/19

Removing label class

Roshan123 Roshan123

2020/12/19

#
I used:- repaint(); GreenfootImage bg=new GreenfootImage ("background_img.png"); bg.scale(400,300); setBackground(bg); Label text=new Label("hello",30); removeObject(text); But now also i m not able to remove label class from background of the world
Jackylein250 Jackylein250

2020/12/19

#
I haven't really understood the context, but I'll try to help you. Setting the background image is typically something you do in the constructor of the world. I assume we are in a World class because you used repaint();. I never used repaint(); but I think it resets the world to the original state. Is this really what you want? To remove an object from a world that you added before you have to keep it as a private instance variable, so you always have a reference to it. Or you could remove all objects of the Label class with removeObjects(getObjects(Label.class)); Also, the Label object should inherit from Actor, so you don't need to reset the world's background to remove it. Just remove the Label object, and you should be good to go.
Roshan123 Roshan123

2020/12/20

#
Ok, thanks for helping me out....
You need to login to post a reply.