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

2014/11/5

Change order of objects (One over the other)

HaselnuesseTo HaselnuesseTo

2014/11/5

#
Hey! I'd like to change the order of my objects. If i reached a special line the order has to change. Could someone help me? :)
danpost danpost

2014/11/5

#
You can use the World class method 'setPaintOrder' multiple times within your code.
HaselnuesseTo HaselnuesseTo

2014/11/5

#
Thanks! Can you give me an example?
danpost danpost

2014/11/5

#
Example for use in an Actor subclass (for an actor that moves from left to right at a speed of 1):
1
if (getX() == 300) getWorld().setPaintOrder(ActorClassName.class);
where 'ActorClassName' is the class of the actor you want on top of other Actor type objects.
Alwin_Gerrits Alwin_Gerrits

2014/11/5

#
It works simply by adding the classes in a certain order. So you would use the command somewhat like this i guess: setPaintOrder(block.class, player.class, enemy.class); The last thing you add is going to be on top. Because it is the last layer added to the world. Please correct if I'm wrong. I see danpost allready reacted while I was typing. Try his idea first. He's better at this then I am XD.
HaselnuesseTo HaselnuesseTo

2014/11/5

#
Ohh sorry! Thank you all! Can be closed, I got it :P
Super_Hippo Super_Hippo

2014/11/5

#
Alwin_Gerrits wrote...
The last thing you add is going to be on top. Because it is the last layer added to the world. Please correct if I'm wrong.
It's the other way around, the first class will be on top of the others, then the second and so on.
You need to login to post a reply.