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

2014/6/10

Help With Paint Order Of Individual Objects

GunShow124 GunShow124

2014/6/10

#
Hi there. I am making a card game where the cards get put into stacks, with the top card facing up. However, occasionally when I play a card, the card goes underneath. Is there anyway to specify the paint order of a specific object of a certain class?
danpost danpost

2014/6/10

#
There is no documented way to have specific objects of a class appear above others. However, currently, there is a non-documented trick you can use to make one appear above another. Remove the object from the world and re-add it back at the same location into the world.
NikZ NikZ

2014/6/10

#
I believe you can use setPaintOrder() from World, but it only handles different classes.
GunShow124 GunShow124

2014/6/10

#
Is there any way to do that from the card itself? When I remove the card and re-add it, it throws a null pointer exception because the card no longer exists in the world. Is there anyway to save the reference of the card in order to re-add it later?
danpost danpost

2014/6/10

#
Your null pointer was probably due the 'getWorld' not being able to get the World object that the actor was in after it was removed from the world. Get a reference to the world before removing the actor:
World world = getWorld();
int x = getX(), y = getY();
world.removeObject(this);
world.addObject(this, x, y);
You need to login to post a reply.