Blending with background in cocos2d-x - cocos2d-x-3.0

I am new to blending in cocos2d-x and couldn't find much on google.
I have white background in my game and i have added red colour sprite "circle.png" on it(empty from centre region) .
Now i want to blend certain parts of circle with background so that it seems to user that the circle is broken from certain parts.

Related

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 :)

Getting Colored pixels of humanStencilTexture from ARHumanBodyManger

I am creating an AR application for iOs using Unity and ARKit 3.
I am using People occlusion sample to detect human bodies.
ARHumanBodyManger has a property called humanStencilTexture which return Texture2D which preview the human body in red and other things in black as shown in this image.
I want to identify the coloured pixels in this Texture.
I used humanStencilTexture.GetPixels() to get all pixels and when I checked these pixels they all black.
Can anyone help me how to check for red pixels?

Sprite-Kit: change the contact points color

The scene background color is white.
In the scene there are two sprite nodes (SKSpriteNode) sprite 1 and sprite 2 with black borders and transparent backgrounds.
sprite 2 moves.
sprite 2 reaches sprite 1 and contacts it.
What I'm trying to do is merging the two sprite contact borders when they contact each other. With other words: I want to change the color of the contact points of both sprites into the scene background color. I tried to do this with the blendMode property. But it seems that the blendMode property works only with a node and his parent.
Does the blendMode property work only with a node and his parent? If yes, is there any way to change the colors of the contact points of two "normal sprite nodes"?
Thanks for any ideas.
EDIT:
the background color is white.
each sprite is transparent and has a border with black color.
when a sprite contacts OR is moving along the border of another sprite, the black color of all contact points of both sprite borders changes to white (that is the background color). The color of all other border points of both sprites stays black.
I put another picture with more details.
Thanks in advance.
Blend mode will only blend textures together, it will not remove that black border unless you are applying something like Xor Blending. The actual sprite would blend to the destinations frame buffer, not the parent, so whatever is below the sprite at the time of rendering it.
Blending the Sprite into the Framebuffer
The final stage of rendering is to blend the sprite’s texture into its destination framebuffer. The default behavior uses the alpha values of the texture to blend the texture with the destination pixels. However, you can use other blend modes when you want to add other special effects to a scene.
You control the sprite’s blending behavior using the blendMode property. For example, an additive blend mode is useful to combine multiple sprites together, such as for fire or lighting. Listing 2-6 shows how to change the blend mode to use an additive blend.
Source: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Sprites/Sprites.html
To achieve what you are looking for, I wouldn't even mess with blending, instead have your sprite broken up into 2 sub sprites, the border, and the inside color.
What I mean by this is lets say you have a circle with radius 10 and a 1 pixel thick. We create a node, that has a child that is just the border with a transparent area at radius 10, and another child that has a radius of 9, which will be filled with white.
Set the borders zposition to 0
Set the inside sprites zposition to 10.
When 2 sprites merge together, here is how drawing will be rendered
Sprite 1 border
Sprite 2 border
Sprite 1 inside
Sprite 2 inside
This will give you the effect you are looking for with the sprites merged together.
Of course, if your inside has transparent and not a solid color then we have a
problem. (Right now you are saying your BG is white, so we do not need transarency, your circle cam be white, but if you want to put a texture on the BG, then we have an issue.)
If you indeed want to keep your circle "transparent", then what you need to do is capture the background underneath before the border gets drawn, and make that the texture of your inner circles

Achieving 1 pixel outline around sprites which changes colour depending on the background?

Here's an example of what I mean: http://38.media.tumblr.com/aa36eac06bebe495f34046d4b2557410/tumblr_n8a8p4dkOb1s6ek46o1_500.gif
In this gif, when the character is on the dark background, his outline is almost black, whilst it retains more colour if the background he's on is the sky one. How can I achieve this in Unity? I don't think it's individual sprites

iPhone cocos2d CCTMXTiledMap tile transitions

I am using cocos2d on the iPhone and am wondering if it is possible to use a texture mask in order to create tile transitions / fringe layer. For example, a grass tile and a dirt tile, I would want a tile that had both grass and dirt in it... Has anyone done this, or is the only way to create one tile for every possible transition?
For those who are curious, you can use masks with the following setup:
First draw the mask which should use a black brush on a transparent background. Draw this with src alpha and one-minus src alpha.
Second, draw on top of the mask the texture that you only want to appear over the mask part (the black brush). Draw this texture with dst alpha and gl_zero.
Third, draw the texture that you want to appear over the transparent part of the mask. Draw this texture with one-minus dst alpha and gl_one.
Using this technique, you don't have to make transition / fringe tiles for all of the possible terrains.