Author Topic: How to choose order to draw sprites of custom entity?  (Read 2279 times)

Diarandor

  • Hero Member
  • *****
  • Posts: 1061
  • Cats are cool! (ΦωΦ)
    • View Profile
How to choose order to draw sprites of custom entity?
« on: December 24, 2015, 12:27:37 pm »
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
« Last Edit: December 24, 2015, 12:42:16 pm by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1185
    • View Profile
Re: How to choose order to draw sprites of custom entity?
« Reply #1 on: December 24, 2015, 01:05:32 pm »
Sprites of an entity are displayed in their creation order.

Diarandor

  • Hero Member
  • *****
  • Posts: 1061
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: How to choose order to draw sprites of custom entity?
« Reply #2 on: December 24, 2015, 01:28:09 pm »
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.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: How to choose order to draw sprites of custom entity?
« Reply #3 on: December 24, 2015, 03:47:09 pm »
The thing is, is it possible to draw something above the hero without (x, y layer + 1) ?
« Last Edit: December 24, 2015, 03:50:17 pm by MetalZelda »

Diarandor

  • Hero Member
  • *****
  • Posts: 1061
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: How to choose order to draw sprites of custom entity?
« Reply #4 on: December 24, 2015, 04:20:46 pm »
@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.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: How to choose order to draw sprites of custom entity?
« Reply #5 on: December 24, 2015, 04:46:28 pm »
Oh, I didn't know that bring_to_front() existed until now. That solved the thing.
« Last Edit: December 24, 2015, 05:41:14 pm by MetalZelda »