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

2013/8/25

Actor of same class to front?

nooby123 nooby123

2013/8/25

#
I have several different actors of the same class. What I want is when I click one of the actors, it will bring it to the front, or above all the other actors. I couldn't find a way since setPaintOrder is only for classes. Any suggestions?
Gevater_Tod4711 Gevater_Tod4711

2013/8/25

#
The front object is always the last one that is added to the world. If you re-add it, it will be in the front:
public void act() {
    if (Greenfoot.mouseClicked(this)) {
        World world = getWorld();
        int x = getX();
        int y = getY();
        world.removeObject(this);
        world.addObject(this, x, y);
    }
}
nooby123 nooby123

2013/8/25

#
I don't want to re-add it. It will reset some of the changed variables to it. I just want to bring it to the front.
nooby123 nooby123

2013/8/25

#
I have thought about that idea though.
Gevater_Tod4711 Gevater_Tod4711

2013/8/25

#
What variables do you mean? If you delete the object from the world and re-add it all the variables of this will have the same values. Why should they be reseted?
nooby123 nooby123

2013/8/25

#
Nevermind, thank you! It works fine, just the way I want it to.
nooby123 nooby123

2013/8/25

#
I thought it would reset it, since they were private variables.
Gevater_Tod4711 Gevater_Tod4711

2013/8/25

#
The variables are only reseted if you create a new instance of the object. The modifiers don't matter there.
You need to login to post a reply.