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
Related
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 :)
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.
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
I need a 'mask' layer that covers the whole screen, with the center part (a circle) to be transparent. Then I can move the mask layer around using touch. User are only able to see the transparent part in the middle.
I don't think a png file can help because the file need to be very large to cover the whole screen.
So is it possible to do it by coding?
i found this online, but don't know much about openGL. http://www.cocos2d-iphone.org/forum/topic/7921.
it would be great if i can use a CCMaskLayer and input with the radius. i can handle the touch event by my self.
the attached png file is expected result, the center part is transparent. i need this to cover my screen, and only show the middle part. the red part is covered.
I write a CCMaskLayer to do the exactly same thing.
https://github.com/smilingpoplar/CCMaskLayer
You may solve this task with cropped circle texture in two ways:
1) Draw sprite with circle texture in screen center and draw another 4 sprites around (on top, bottom, left and right sides) with small red texture but scaled to cover all screen.
2) (more elegant but harder to implement) Make your mask layer fullscreen but adjust texture coordinates. In details:
set wrap mode to GL_CLAMP_TO_EDGE to your circle texture
adjust texture coordinates of your layer vertices (to do this you need to subclass base CCLayer):
Here v means vertex position and t - texture coordinates. You need to set correct texture coordinates for four corner vertices of layer. For future if you will want to drag circle you will need to add some offset values to texture coordinates.
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.