2D Toolkit Forum

2D Toolkit => Support => Topic started by: SalmonPunch on December 01, 2014, 06:41:51 pm

Title: Dynamically hide part of a sprite.
Post by: SalmonPunch on December 01, 2014, 06:41:51 pm
I want certain pixels of the player's sprite to be hidden if those pixels overlap with something that is supposed to be "Above" him (IE, if he is standing behind a building, and half his body is behind the building, then that half is not drawn. Is there any way to do this efficiently with 2DToolkit?

I know there is Texture2D.SetPixel, but I have no idea how to use it in this context.

Thanks in advance.
Title: Re: Dynamically hide part of a sprite.
Post by: Trigve on December 01, 2014, 08:32:29 pm
You could achieve this with sorting layers and sorting order in the given layer. Or setting the different Z position for the building and the player. I think there something about this in the documentation in the sprite section.
Title: Re: Dynamically hide part of a sprite.
Post by: SalmonPunch on December 01, 2014, 08:58:46 pm
I would prefer the technologically advanced solution since it will save me a lot more work in the long run, but I will investigate layers if I can't get this method to work.

so back to the original question, could I use SetPixel to achieve this?
Title: Re: Dynamically hide part of a sprite.
Post by: Trigve on December 01, 2014, 09:15:27 pm
You could but it would be slow and you will need to somehow find  exactly which pixels to "hidden". And I don't find the SetPixel method particularly nice nor the "technologically advanced solution".
Title: Re: Dynamically hide part of a sprite.
Post by: unikronsoftware on December 02, 2014, 09:29:13 am
Sorting layers is the preferable solution here, SetPixel is incredibly (unusably) slow.