Search code examples
iosobjective-ccolorssprite-kittextures

Is it possible to change texture hue programatically in Spritekit project?


I am interested in to how change hue of the texture in efficient way ? I am experimenting to create space dust which will change it's color every few seconds with nice, smooth transition from one color to another.

I find this possible in few ways:

  • Using core image like in this example. But I don't know how will this work in combination with Spritekit...

  • Using particle emitters to create space dust and change color of particles over time using particleColorSequnece property.

  • And easy one that came up on my mind , while playing with Photoshop, which is using two same, but differently colored images, one over another, and changing the opacity of the topmost one.

This gives me the effect I want, and actually looks fabulous, but is there any better way ? Maybe using SKTexture? In this particular case, I just need to change from one color to another , but what would be an efficient way to do this when multiple changes are required one after another ? This way, my third example requires additional images...

Here is the link which most closely describe what I am trying to accomplish. Just look how space dust changes its color overtime(from dark blue to purple and later to green or orange). I suppose this is done programatically... I would like to ask moderators to remove a link if it is not suitable to post it here. Thanks!


Solution

  • It is kind of a hard questions to answer and is rather subjective, however...

    I personally would do the Emitter Node approach, because it seems like it is built for the type of use you are looking for and could have some cool effects trailing behind.

    With that being said you specifically asked about changing the hue and colorBlendFactor might be what you are really looking for. I don't have a great link for it, but this might get you pointed in the right direction. You can see how they are blending colors to get the desired result.

    Your solution with changing the alpha of two separate colors doesn't sound like a bad approach either.

    Hopefully that helps and good luck =)