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

2013/12/8

How to set paint order for specific objects based on posision of them?

Entity1037 Entity1037

2013/12/8

#
I'm trying to make an Isometric game based on theoretical physics and I need some isometric graphics to go along with it. I'm trying to make the actor draw behind the block if he's below or to the left of it, and above if he's above or to the right of it. Does anyone know how this can be done? (I would prefer doing this instead of having to double the amount of actors and just make another actor that acts as the background for each block).
danpost danpost

2013/12/8

#
I think to do what you want to do properly, you need all actors to have a 'depth' (or 'z' location) value. Then by comparing the 'z' locations, you can determine the paint order.
Entity1037 Entity1037

2013/12/8

#
OK. Wait, so... how exactly do I set the paint order of individual actors? Or Do I just insert them in a certain order so that the ones with a higher z value get inserted last?
danpost danpost

2013/12/8

#
With 'higher z value's given to those closer objects, then yes.
Entity1037 Entity1037

2013/12/8

#
OK then, so is it possible to set the paint order of individual actors within the world without re-inserting them?
danpost danpost

2013/12/9

#
Well, you are not using 'setPaintOrder' to do it; you have to sort the actors in your world according to the value of their 'z' field and then 'addObject' them into the world so that they are listed internally properly and painted (or refreshed) in that order.
Entity1037 Entity1037

2013/12/9

#
Well I can't exactly re-insert the actors because they use timers and variables.
danpost danpost

2013/12/9

#
Entity1037 wrote...
Well I can't exactly re-insert the actors because they use timers and variables.
The timers and variables will still be active (will not be affected) provided you do not use the 'new' keyword to create a new instance of the object and add that into the world instead of the currently active object.
Entity1037 Entity1037

2013/12/9

#
Oh, I didn't know you could do that. Thank you!
You need to login to post a reply.