Hello Guest

Author Topic: tk2dSprite Change Shader Programatically  (Read 5431 times)

DahongPunyal

  • Newbie
  • *
  • Posts: 15
    • View Profile
tk2dSprite Change Shader Programatically
« on: February 03, 2014, 03:53:59 am »
Is it possible for a tk2dSprite to change its shader at runtime?

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite Change Shader Programatically
« Reply #1 on: February 03, 2014, 10:56:34 am »
it is possible, but you'll have to create a copy of the material yourself. The next time the sprite is changed it will reapply the original material, so you will need to manage that yourself. You can use the SpriteChanged event to deal with that.

DahongPunyal

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: tk2dSprite Change Shader Programatically
« Reply #2 on: February 04, 2014, 01:39:51 am »
Thanks for the reply.

Can you give me a code snippet for that?

I can't find the SpriteChanged event, maybe because I'm using an older version of tk2d?

DahongPunyal

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: tk2dSprite Change Shader Programatically
« Reply #3 on: February 04, 2014, 02:48:46 am »
I found a way to do this. I'm changing the sprite's renderer shader to other shader and it works fine. Thanks! We can close this now.

DahongPunyal

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: tk2dSprite Change Shader Programatically
« Reply #4 on: February 04, 2014, 10:33:04 am »
Sorry, I thought we can close this thread now. But, I tried to load it on iPad Mini and it didn't work. All I can see are pink assets. :(

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite Change Shader Programatically
« Reply #5 on: February 04, 2014, 10:35:20 am »
You probably didn't put the shader in resources, or the shader isn't supported.

DahongPunyal

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: tk2dSprite Change Shader Programatically
« Reply #6 on: February 05, 2014, 01:17:11 am »
Meaning, I have to import tk2d's shaders to the resources folder for it to work? Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite Change Shader Programatically
« Reply #7 on: February 05, 2014, 10:33:39 am »
It implies your shader is likely null when you assign it. I don't know how you get the shader to swap it - you need to check that its not null and if it is, work out why.