Solarus-Games English Forum

Solarus => Development => Topic started by: YoshiMario2000 on September 18, 2016, 09:25:30 PM

Title: [Help] Sprite rendering
Post by: YoshiMario2000 on September 18, 2016, 09:25:30 PM
Wondering If I can change they way sprites are rendered. Rather than having a sprite that has a higher Y-value than the hero be rendered over them, I want the sprite to be rendered beneath the hero.
Title: Re: [Help] Sprite rendering
Post by: Diarandor on September 19, 2016, 12:59:27 AM
Sprites are currently attached to entities, so I guess you are trying to draw some entity under the hero, isn't it? If so, yes, it is possible to do so, and the Lua API should solve your problems. If you still have problems to do it, then you should explain with more details what you are trying to do, so that we can help you.
Title: Re: [Help] Sprite rendering
Post by: Christopho on September 19, 2016, 08:51:01 AM
If the entity is a custom entity, there is a function custom_entity:set_drawn_in_y_order() (http://www.solarus-games.org/doc/1.5/lua_api_custom_entity.html#lua_api_custom_entity_set_drawn_in_y_order) to specify if you want it to be displayed in Y order or in Z order.
Title: Re: [Help] Sprite rendering
Post by: YoshiMario2000 on September 19, 2016, 10:35:18 PM
Quote from: Christopho on September 19, 2016, 08:51:01 AM
If the entity is a custom entity, there is a function custom_entity:set_drawn_in_y_order() (http://www.solarus-games.org/doc/1.5/lua_api_custom_entity.html#lua_api_custom_entity_set_drawn_in_y_order) to specify if you want it to be displayed in Y order or in Z order.
Ah, so THATS where I saw something along the lines of that, I thought that It applied to all entities.
Guess I was wrong...

Quote from: Diarandor on September 19, 2016, 12:59:27 AM
Sprites are currently attached to entities, so I guess you are trying to draw some entity under the hero, isn't it? If so, yes, it is possible to do so, and the Lua API should solve your problems. If you still have problems to do it, then you should explain with more details what you are trying to do, so that we can help you.
What I'm trying to do is to have a block that has a higher Y-value than the hero to be displayed underneath the hero.
I'm working with the side scrolling script and am displaying the tiles in a similar fashion to Kirby superstar saga. Which Includes entities like blocks. The behavior is fine other than the odd rendering of the sprites when the hero overlaps the block.
Title: Re: [Help] Sprite rendering
Post by: Christopho on September 20, 2016, 12:14:11 AM
If your block has a sprite whose size is greater than 16, then it gets displayed in Y order. Like statues in my games. This will be customizable one day, but as a workaround you can always make a sprite higher than 16 pixels with simply some transparency above :)
Title: Re: [Help] Sprite rendering
Post by: Diarandor on September 20, 2016, 12:26:58 AM
QuoteWhat I'm trying to do is to have a block that has a higher Y-value than the hero to be displayed underneath the hero.
I'm working with the side scrolling script and am displaying the tiles in a similar fashion to Kirby superstar saga. Which Includes entities like blocks. The behavior is fine other than the odd rendering of the sprites when the hero overlaps the block.

If I understood correctly, you are trying to make built-in blocks in 2D side-scrolling and allow to display the hero correctly over it, isn't it? I still do not understand which is the problem, unless it is what Christopho says: that the sprite of your block is too big. If that is the case, you could use a custom entity instead, but the simplest way would be to use a 16x16 sprite. If you still have some problem, we would need more info to help more; if so, recall that an image is worth a thousand words.
Title: Re: [Help] Sprite rendering
Post by: YoshiMario2000 on September 20, 2016, 12:43:35 AM
Quote from: Diarandor on September 20, 2016, 12:26:58 AM
an image is worth a thousand words.
(http://i.imgur.com/PtfakO8.png)
Title: Re: [Help] Sprite rendering
Post by: Diarandor on September 20, 2016, 01:43:46 AM
Thanks for the image! This shows that Christopho was right, your sprite is not 16x16, and therefore you will need to use some "ugly" workaround (or wait until Solarus adds more customization to the built-in blocks). I give you two possible workarounds that should work, but you will need to work a bit:

-One of them is just using custom entities instead of built-in blocks. Note that this allows to use several sprites for a custom block, which would solve your problem because you could display the above part behind the hero. But you would need to code all the block features in Lua...

-The other workaround is to create, for each block, a rectangular and (traversable) custom entity with the above part of the sprite. That custom entity should follow the block (that can be done with a timer which is called each millisecond, for instance). These custom entities can be easily created from the map script using a loop on all entities of block type.
Title: Re: [Help] Sprite rendering
Post by: YoshiMario2000 on September 20, 2016, 02:07:33 AM
Well, Seeing as that improved built-in functionality probably won't happen until 1.6 or something, I think I'll just go the custom entity route. Shouldn't be hard right?
Title: Re: [Help] Sprite rendering
Post by: Diarandor on September 20, 2016, 09:18:11 AM
I think both solutions are easy. The second solution requires less work, so it is probably better and quicker. Anyway, it's your choice.
Title: Re: [Help] Sprite rendering
Post by: MetalZelda on September 21, 2016, 12:10:25 PM
Creating a custom-entitified block is relatively easy, you might need Diarandors Direction and animation fix first, and disable the y-order drawing when the block is at a certain point

This is the recommanded workaround as for now, if you plan to use a block which has a pixel value higher then 16x16