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

2013/2/10

Need help with PaintOrder

Upupzealot Upupzealot

2013/2/10

#
My question is how can I set paintorders between Actors that belongs to the same subclass of Actor. For example, I'm writing a GUI class, and I want to set the Window witch is clicked most recently on the top of the screen. How can I do that. I had an idea that I may remove the Window and add it to the World again, but it seems that the Actors who is just removed chould not be added to the same world again. So, could anyone help? Thanks.
Gevater_Tod4711 Gevater_Tod4711

2013/2/10

#
Your idea was right. It should work like this. Probably you have removed your actor and tryed to readd it to the world like this:
getWorld().removeObject(this);
getWorld().addObject(this);
But this doesn't work because when you remove the actor from the world it has got no references to the world and the method getWorld() will return null in the second call. So you better try it like this:
World world = getWorld();
world.removeObject(this);
world.addObject(this);
danpost danpost

2013/2/10

#
I do not know why you would think that you cannot add a removed object back into the world.
World world = getWorld();
int x = getX();
int y = getY();
world.removeObject(this);
world.addObject(this, x, y);
Upupzealot Upupzealot

2013/2/10

#
addObject(base1, 300, 200);
addObject(base2, 320, 200);
removeObject(base1);
//repaint();
addObject(base1, 300, 200);
this this what I did in the constructor of my world, in order to let base1 cover base2. but base1 just disappear...
Upupzealot Upupzealot

2013/2/10

#
Thanks you two above for reply. The problem is that I overrided addObject() and removeObject() method in my world, and it turns out that is the bug. Again, thanks very much for helping.
You need to login to post a reply.