How to get what percentage of screen Is covered by sprite mask in unity? - unity3d

I'm making a scratch effect using line renderer and sprite masks. I want to calculate what percentage is scratched on the screen. How can I do it?
Or else any alternative solution?

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.

How can you get the 3D space coordinates of the 4 corners of an ImageTarget in Vuforia Unity?

I am able to detect images in Vuforia images and overlay 3d objects on them. But I want to draw borders around the ImageTarget.
The problem is that I can only get the center of it such as,
productTarget.transform.position
How can I get the corners of the image ? It is simply a 2D image but Vuforia doesn't have anything to help with this.
There is no way to detect coordinates of the corners, but you can manually calculate it.
This will help you to get the height and width of the image
for example: coordinates of upper left corner will be center - (width/2) - (height/2)
I recommend you just make flat border which you want, and then just resize it on tracking image, because its scale is always the same and vuforia only moves the camera.
image
border
after tracking just child border to image
after parenting

How do I disable resampling in the SpriteKit framework?

If I have a scene, let's say is 100x100. When I scale it up to the size of the phones screen, it gets all blurry, like MIP-Mapping. How can I make it so it is just pixelated when I scale up the scene?
Change each affeced texture's filteringMode to nearest filtering. Refer to https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKTexture_Ref/Reference/Reference.html#//apple_ref/occ/instp/SKTexture/filteringMode

ios game make a mask layer effect

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.

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.