2D Toolkit Forum

2D Toolkit => Support => Topic started by: DahongPunyal on February 03, 2014, 03:53:59 am

Title: tk2dSprite Change Shader Programatically
Post by: DahongPunyal on February 03, 2014, 03:53:59 am
Is it possible for a tk2dSprite to change its shader at runtime?

Thanks!
Title: Re: tk2dSprite Change Shader Programatically
Post by: unikronsoftware 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.
Title: Re: tk2dSprite Change Shader Programatically
Post by: DahongPunyal 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?
Title: Re: tk2dSprite Change Shader Programatically
Post by: DahongPunyal 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.
Title: Re: tk2dSprite Change Shader Programatically
Post by: DahongPunyal 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. :(
Title: Re: tk2dSprite Change Shader Programatically
Post by: unikronsoftware on February 04, 2014, 10:35:20 am
You probably didn't put the shader in resources, or the shader isn't supported.
Title: Re: tk2dSprite Change Shader Programatically
Post by: DahongPunyal 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!
Title: Re: tk2dSprite Change Shader Programatically
Post by: unikronsoftware 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.