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

2013/9/9

setPaintOrder(class... c)

Kartoffelbrot Kartoffelbrot

2013/9/9

#
I have three Actors a, b and c. I want to that: a is above b b is above c c is above a, when it isn't behind b Is that possible?
davmac davmac

2013/9/9

#
I'm afraid it's not. The best you could do is change the paint order yourself if you detect that the c isn't touching a b, for instance. If there are multiple c objects, then this won't work of course; in that case you could introduce a fourth class 'd' which is a clone of 'c', and have its paint order above a; when a c isn't touching a b, you remove it and replace it with a d; when a d is touching a b, remove it and replace with a c.
danpost danpost

2013/9/9

#
You could add boolean(s) to each class (in a: aboveB; in b: aboveC; and in c: aboveA and behindB) and, not using these classes in 'setPaintOrder', remove and replace the actors in the world when needed to be placed above another. For example, in A class:
if (getOneIntersectingObject(B.class) != null && !aboveB)
{
    int x = getX(), y = getY(), w = getWorld();
    w.removeObject(this);
    w.addObject(this, x, y);
    aboveB = true;
}
if (getOneIntersectingObject(B.class) == null && aboveB) aboveB = false;
Do similar for the other classes (the c class will be a bit more involved for what it does).
Kartoffelbrot Kartoffelbrot

2013/9/9

#
Thanks
davmac davmac

2013/9/9

#
danpost, that might work, but you're relying on undocumented behavior which you should avoid if possible. It's not specified anywhere that the objects will be painted in the order they are added into the world, and that it happens now is an implementation detail which might change.
Kartoffelbrot Kartoffelbrot

2013/9/9

#
I understand (like building complicatied things in Minecraft (if you know it)).
davmac davmac

2013/9/9

#
Just to clarify: I'm not saying removing and re-adding actors is a bad suggestion in itself, just that you need to be aware of the potential issue with forwards compatibility.
You need to login to post a reply.