If there is a sprite with several children to be cut off, how to do it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zhagsenkk

https://forum.godotengine.org/36024/if-there-is-a-group-of-sprites-to-be-cut-off-how-to-do-it

I can cut off a sprite or a texture by shader, but if there is a sprite with several children to be cut off, how to do it?

ps: Easy and flexible way to make sprite masks · Issue #23763 · godotengine/godot · GitHub

Why are you making a duplicate of your question?

SIsilicon | 2018-11-22 12:01

sorry but I just think that no one will answer the former question…

zhagsenkk | 2018-11-22 12:20

Wouldn’t help if you made the exact same question.

Check out the answer to my question about getting your questions answered.

SIsilicon | 2018-11-22 16:51

Hi, @zhagsenkk have you managed to solve the problem?

MysteryGM | 2018-11-24 17:05

:bust_in_silhouette: Reply From: MysteryGM

I can cut off a sprite or a texture by shader, but if there is a sprite with several children to be cut off, how to do it?

This makes more sense. There is two basic ways to do it.

1.) If every sprite has it’s own material, it will need to set the values per-material. So you will need to have a code that looks like this:

extends Node2D

func _ready():
	for EachChild  in self.get_children() :
		var TheMaterial = EachChild.material as ShaderMaterial
		TheMaterial.set_shader_param("Clip", 0.1)

2.) Actually there is a more efficient way to do it.
What you need to know is that every material will have a set of it’s own material properties.

What this means is that if the material is shared between sprites, like in a sprite sheet or texture atlas, they will all be effected at the same time.

Here is a example of sprites sharing a material:
enter image description here

A Zip file, with a Godot example. I use Godot 3.1 Alpha2

Thx. The effect i want to make is:
alpha.png - Google Drive
The sprite with several children is influenced as a whole. Like they are one sprite.
this question may be the same issue:
how to apply a shader to a group of nodes ? - Archive - Godot Forum

zhagsenkk | 2018-11-25 08:20

OK, what you need is 2 UV channels. 1 for the sprite image and 1 for the mask. The mask will probably work in Global space and tile. I will make an example for you.

MysteryGM | 2018-11-25 18:56

Hi, I was just making the shader when I realized you wanted a UI-Mask.Talk about miss communication.
In Godot the Light 2D is used for masks like this:
enter image description here

The way it works is you set the light2D node to Mask. It uses the Alpha channel of the image to make the mask, so use PNG images.
When using more than One you will want to use the layer settings.
enter image description here

MysteryGM | 2018-11-25 20:07

tanks! can you supply your project?

zhagsenkk | 2018-11-26 14:13