Swift 3 Change Hue Of Sprite - swift

In my game, i have a wizard sprite.
I would like to be able to change the colour of this sprite programatically so put a faded color over the top to change the color.
So when the player changes the character, the sprite color changes.
Any ideas on how to do this?

I would just convert the colorable portion to greyscale and use SKAction.colorize the sprite.
this works very well, I use it all the time, however you may have to create a wizard overlay of the red and yellow parts so they don't get colorized as well

Related

Unity, 2D, Hiding light sources outside of field of view

I'm playing with light 2D in unity and struggling to achieve proper lighting. I want to create a top down shooter with rendering only field of view of a playable character. I have two light sources in that scene: That yellow rectangle with eyes and a second one on the left in the shadow. My goal is to hide any object which is not in a field of view of that yellow character - even light sources, but to keep the light that's visible, like additional shadow effect, light effects and so on. Second screen is edited in paint to show what I'm aiming for. Do you know how to achieve that effect?
Actual result
Desired result
Leaving an answer because I cannot yet leave a comment. One way I can imagine doing this is by using a 2D line renderer instead of casting shadow from your Yellow Light source. Make the line thick and black and it's placement is defined such that the starting point would be the object (wall, obstacle etc.) and the line will go in opposite direction to some feasible extent of where the Yellow Light source is.

Unity 2D display "flash effect" above tiles

I want to apply a brighten effect above my scene.
My scene contains tiles, and I want to perform white flash for a few frames by code.
I have already tried this code:
private Tilemap tm;
...
tm = GetComponent<Tilemap>();
tm.color = new Color(0.5f,1.0f,1.0f,1.0f);
This code darkens the scene by a certain color amount, but I wish to brighten it.
Your code is not working because in Unity if you render an image (in your case tile) the original color of the image is when its color is white (255,255,255,255).
It means that if you change the color of an image it will add this color to this image.
For instance, if you set the color of an image to red, the image colors will become more similar to red than the original image.
As I see it you have 2 ways to perform the white flash:
A) Add another image of a white rectangle that covers all the screen and set it's alpha color to a low number (the lower the number the lighter flash effect).
In the editor disable this object's renderer and when you want to perform a flash effect enable this object from the code (You can improve this with animations or code to get a smooth flash animation).
B) Install the package "2D Light". This is an experimental package that allow you to render 2d light.
This package contains a lot of components that allow you to stimulate light.
I have found a way to do this.
I created a new PNG that only contains white shapes on a transparent background.
There are about 20 pieces that match the shapes of my level tilemap.
Now I just create a new (white) tilemap above the level tilemap in the shape of the highlight.
Then I set the alpha of the white tilemap in code.
It works :)

Incorrect white matte behind antialiasing on imported sprites

I'm importing a sprite into Unity, and adding it to a Screen Space Overlay canvas to use for a UI.
The image I'm importing looks exactly as I want it, but in Unity the anti-aliased edges look like they're going to a white background color, instead of just fading over whatever is actually behind them.
I'm using these import settings:
I'm using a default UI/Image component to add it to the canvas.
This is the image I'm importing - it's a 32 bit PNG exported from Fireworks: (also shown over a black background)
Just to confirm, this looks fine everywhere else in Unity, preview panels, pickers etc. I am packing this sprite using the built in Sprite Packer if that changes anything.
And the final result:
How can I get rid of these artifacts on the corners?
The problem was the RGB values of the transparent pixels. By default they are white, and any scaling operations cause this white color to be blended with the partially transparent pixels.
I essentially made a slightly larger version of the button background shape, put it in a layer behind everything, and then wrote back into the alpha channel making it transparent. This means that the neighboring pixels are then the same color as the partially transparent ones.
The end result:

Unity 2D: Irregular shape window to a different background world?

I want to make an irregular shape display its colors from a different set of images. Currently, I have a flashlight represented by an irregular shape (kite shaped) that when casted over an area, certain objects appear. When the shape is removed, the items disappear. Now, I want to have the background that is within this irregular shape to display an altered version of the background.
I am planning to use a RenderTexture to get its info from a camera that views the flashlight's corrosponding location in the other world, and then use this image as the basis of the flashlight's altered background. However, when I try this, the flashlight shows black instead of the other world. When I texture a plane, the RenderTexture works properly. Anyone have any ideas how to accomplish this?

cocos2d screen effect

I am working on my iPhone game using cocos2d. I want to implement the effect: when my hero dies, the screen gradually turns to black/white/grey. That is, all the UI elements and game sprites' color turn black/white/grey. Could anyone tell me how to do that? I have tried to add a CCColorLayer as a mask, but that doesn't look good. And if you add another image for each elements, the size of the app will double. So any other methods to do this?
Have you tried CCTintby ?
http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_tint_by.html
It tint's sprites by a colour. You could do it on every child of your gameLayer.
Maybe you can render your scene to a texture and then manually convert the texture's pixels color to gray. Then render the texture to the screen.