How to choose order to draw sprites of custom entity?

Started by Diarandor, December 24, 2015, 12:27:37 PM

Previous topic - Next topic
December 24, 2015, 12:27:37 PM Last Edit: December 24, 2015, 12:42:16 PM by Diarandor
How can I choose the order to draw the sprites of a custom entity? I mean, how can I draw a sprite above/below other sprites of a given custom entity?

Until now, the only way I found to simulate this was to create a new custom entity with the new sprite, set it to draw on Y-order, and put it in position (x,y+2,z), where (x,y,z) is the position of the original entity; also we need to update the position to follow the original entity. I don't like to have to use this trick each time I want to draw a sprite avobe... Is there some other way to do it at present?

EDIT: just in case, I opened an issue for this, here: https://github.com/christopho/solarus/issues/809
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Sprites of an entity are displayed in their creation order.

Ok, thanks. I solved my problem by creating the sprites in a different order.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

December 24, 2015, 03:47:09 PM #3 Last Edit: December 24, 2015, 03:50:17 PM by MetalZelda
The thing is, is it possible to draw something above the hero without (x, y layer + 1) ?

@MetalZelda: At present you cannot add sprites to the hero, so the only way to do it is to create a custom entity and make it follow the hero.

You can use a layer above the hero, as you say, to draw the entity. But that is not a good solution because there might be some kind of ground or wall on the layer above the hero, and in that case the hero would no be shown (he would be under that ground) but your entity would be shown. That is not a good behaviour for the sprite. So the best solution is to create the custom entity with the sprite in the same layer as the hero (and in that case you need to use my trick to display it above the hero).

Actually, that trick is what I used in my own script to allow carrying custom entities which are shown above the hero (and still they are in the same layer).
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

December 24, 2015, 04:46:28 PM #5 Last Edit: December 24, 2015, 05:41:14 PM by MetalZelda
Oh, I didn't know that bring_to_front() existed until now. That solved the thing.