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

2015/9/30

Location based paintOrder

PhoebeZ PhoebeZ

2015/9/30

#
Hello, I would really like to find a way to set the paint order of individual objects. It would make my forest look much more realistic. Currently I have this:
if(isTouching(WalnutTree.class))
        {
            wClose = (WalnutTree)getOneIntersectingObject(WalnutTree.class);
        }
        if(isTouching(WalnutTree.class) && wClose.getY() + 30 < getY())
        {
            getWorld().setPaintOrder(Walnut.class, RedPlum.class, YellowPlum.class, RingTailedLemur.class, WalnutTree.class);
        }
        if (isTouching(WalnutTree.class) && wClose.getY() + 30 > getY())
        {
            getWorld().setPaintOrder(Walnut.class, RedPlum.class, YellowPlum.class, WalnutTree.class, RingTailedLemur.class);
        }

        if(isTouching(RedPlumTree.class))
        {
            rClose = (RedPlumTree)getOneIntersectingObject(RedPlumTree.class);
        }
        if(isTouching(RedPlumTree.class) && rClose.getY() + 30 < getY())
        {
            getWorld().setPaintOrder(Walnut.class, RedPlum.class, YellowPlum.class, RingTailedLemur.class, RedPlumTree.class);
        }
        if (isTouching(RedPlumTree.class) && rClose.getY() + 30 > getY())
        {
            getWorld().setPaintOrder(Walnut.class, RedPlum.class, YellowPlum.class, RedPlumTree.class, RingTailedLemur.class);
        }
etc... Which works for one of my players, but when they both try to move through the forest only one of them can do it at a time. It also looks a bit strange because every tree of that class changes when the actor is near one. The only thing I can think to do is to make each tree a different class but that would be a huge pain in the ass. Not to mention I spent a long time making the trees randomly spawn in so they wouldn't be touching which is why I am using the close variables (if anyone is interested in seeing how to do that let me know, I am just barely starting to learn so there may be an easier way to do it but it took me some time to reason it out so I may just leave it). If anyone can think of a way to set the paintOrder of individual objects please let me know! I am dying to figure it out. Thanks! p.s. I don't think I mentioned the desired effect is to have the actor in front of the tree when the y coordinate is larger than the trees y and behind the tree when it is smaller just in case anyone was unclear on the question or couldn't tell what was going on in my code. What I have now works decently but only for one actor as I mentioned.
You need to login to post a reply.