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

2020/1/2

I need help

Schizorenius Schizorenius

2020/1/2

#
I program a game. In this game you run on a street and to simulate speed, the stripes in the middle of the street are objects, which move from the top to the bottom. The problem is that they move over the player. How can i put them in the background? The street is also an object, so the stripes has to be over it. I'm happy if you can help me!
AdiBak AdiBak

2020/1/3

#
You can use the setPaintOrder method (found in the world API): public void setPaintOrder(java.lang.Class... classes) Set the paint order of objects in the world. Paint order is specified by class: objects of one class will always be painted on top of objects of some other class. The order of objects of the same class cannot be specified. Objects of classes listed first in the parameter list will appear on top of all objects of classes listed later. Objects of a class not explicitly specified effectively inherit the paint order from their superclass. Objects of classes not listed will appear below the objects whose classes have been specified. Parameters: classes - The classes in desired paint order So, for example, public class MyWorld extends World { public MyWorld(){ setPaintOrder(street.class, stripes.class, player.class); } }
danpost danpost

2020/1/3

#
AdiBak wrote...
setPaintOrder(street.class, stripes.class, player.class);
I am quite sure you meant: setPaintOrder(player.class, stripes.class, street.class); Also, the super constructor call would need to be called prior to this line in that constructor.
You need to login to post a reply.