Cocos2d mask layer (tilemap lighting) - iphone

I'm trying to add lighting to a certain extent within my tilemap based iPhone game. For lack of a better example, I'm trying to add minecraft style lighting - the further a tile is from the light source the greater "dark" tint it has.
The most efficient way I can think of doing this would be to add some type of mask over the tilemap layer in order to create this effect and simply move the masks with the tilemap as the player moves around.
I haven't been able to find any documentation on how to add masks to an entire layer, is this possible? Or is it bad practice? Or can you think of a better possible method for achieving this effect?

The simplest and most efficient solution would be to modify the color property of a tile. By default all nodes have the color "white" and by applying gray colors between black & white you'll be able to control the brightness of the tile.
Note however that when you do treat a tile like a CCSprite, cocos2d will change the tile from its basic implementation and change it into a CCSprite. This may become a performance and/or memory issue. Each CCSprite instance was 420 Bytes last time I checked in cocos2d 0.99.

Related

What is a good way to have a 2d battle royal circle with an adjustable center and radius in Unity?

I am having trouble creating a battle royal zone in unity. I want it to be translucent and cover the map with a masked circle in the middle. However, I dont know if there is any way to control the radius of this mask which is something I need to do regularly. Does anyone know how to achive these results?
It should look like the the map view from Fortnite BR.(https://assets.rockpapershotgun.com/images/2019/01/fortnite-small-storm-690x388.jpg/RPSS/resize/690x-1/format/jpg/)
There are a few ways to achieve this effect.
The first and easiest is using the built in Mask, if you are using UI to render the minimap. You can also create a custom UI mesh, as described here for example.
The last option is a (custom) shader. You can download the built-in shaders here and copy over the UI one. Then you have to add your own logic to the fragment shader, something that looks for the Length of the distance of the current UV coordinates and the circle, and if thats smaller than the radius it must be inside. In that case, either clip or set the alpha to 0.

Unity - Guidelines for color isolation effect

I would like to highlight two objects in Unity so that they stand out. But instead of actually highlighting them, which I already know how to do, I would instead like to have some kind of color isolation effect, like the one we can see in the picture below :
However, I really have no idea about how I could acheive this !
Could I use some post processing effects to remove the saturation, expect for a set of objects ?
Should I instead desaturate all the materials of all the objects in the scene and also desaturate the sun color ?
Should I apply to all the other objects in the scene a shader that only renders grayscale colors ?
Could you point me into the right direction ? Thank you.
One approach would be:
- Add a desaturate post process to your main camera and set its culling mask to everything(but turn off the effect)
- Create a second camera, make it a child of the first one (so it keeps the same rotation and position) and set its culling mask to something else (a layer where you will place your highlighted objects)
- When an object needs to be highlighted, add it to the highlights layer and desaturate the main camera. The object will stay colored because it is rendered by the camera that does not have the desaturation effect.
You'll have to play with the "Clear Flags" option of both cameras to get this to work correctly
Still using LWRP Post Processing stack, but I'd add a Color Grading effect and use that to 'tune' your unwanted colours to grey.

Unity: Filter to give slight color variations to whole scene?

In Unity, is there a way to give slight color variations to a scene (a strain of purple here, some yellow blur there) without adjusting every single texture? And for that to work in VR stereo images too (and ideally in semi-consistent way as one moves around, and perhaps also without having to use computing-heavy colored lights)? Many thanks!
A simple way to achieve this if your color effect is fixed would be to add a canvas that renders a half transparent image to the whole screen. But I suppose that you might prefer some dynamic effect.
To achieve this, look at Unity's post processing stack. It allows you to add many post process effects, such as chromatic aberation and color grading, that might allow you to do what you want

Unity3D - Make texture edges not stretch

I've been searching around for this one for a bit, and unfortunately I can't seem to find any good, consistent results. So, in the Unity UI system, buttons can stretch without becoming pixelated or distorted. This is because the texture is split up into 9 parts - the corners, middle, and sides.
This works because the button's middle and sides are stretched, but not the corners. Then, the button appears not pixelated, at any dimension.
So, the question is as follows: How can I do the same thing for a transparent, unlit texture in 3D space? I have a speech bubble texture on a flat plane that I know how to re-scale to fit the text in the speech bubble.
I've set the texture type to Multiple Sprite, and divided it up into 9 parts. However, I cannot seem to find where I can set the texture to act like the UI button does, and I'm not sure that this is even possible in this way in 3D space.
Is there a way, or should I just make the different parts of the texture different objects, and move them together? That would seem very inefficient and ugly compared to this.
To accomplish what you are asking, you would need to create tiles for this speech bubble and then write a script that procedurally builds a speech bubble based on the plane's scale value. You could also try just changing the texture's Filter Mode to Point.
However I really don't think you should be using textures for this anyway. Why not just use a Unity Canvas and set the Render Mode to World Space? Then you can just set your text box to be a sprite, not a texture, and set its filter mode to Point (See below). This would also make it a lot easier for when you want there to be text in the speech bubble later on.

OpenGL, primitives with opacity without visible overlap

I'm trying to draw semi-transparent primitives (lines, circles) in OpenGL ES using Cocos2d but can't avoid the visible overlap regions. Does anyone know how to solve this?
This is a problem you usually come across pretty often, even in 3D.
I'm not too familiar with Cocos2D, but one way to solve this in generic OpenGL is to fill the framebuffer with your desired alpha channel, switch the blending mode to glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA) and draw the rectangles. The idea behind this is that you draw a rectangle with the desired transparency which is taken from the framebuffer, but in the progress mask the area you've drawn to so that your subsequent rectangles will be masked there.
Another approach is to render the whole thing to a texture or assemble the shape using polygons that don't overlap.
I'm not sure whether Cocos2D supports any of theseā€¦
I do not know what capabilities Cocos2D specifically provides, but I can see two options,
One, do not overlap like that, but rather construct more complex geometry such that each pixel is only covered once,
Two, use stencil buffer to create a mask as you draw, and to reject any pixels that are already masked.