Hello Guest

Author Topic: Dynamically hide part of a sprite.  (Read 3774 times)

SalmonPunch

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Dynamically hide part of a sprite.
« 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.

Trigve

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Dynamically hide part of a sprite.
« Reply #1 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.

SalmonPunch

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dynamically hide part of a sprite.
« Reply #2 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?

Trigve

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Dynamically hide part of a sprite.
« Reply #3 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".

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dynamically hide part of a sprite.
« Reply #4 on: December 02, 2014, 09:29:13 am »
Sorting layers is the preferable solution here, SetPixel is incredibly (unusably) slow.