Skip to content

Commit 6b1bd26

Browse files
Merge pull request #9817 from ShawnHardern/update-playing-videos-csharp
Add C# example to Playing videos
2 parents c9667d9 + 2a252ae commit 6b1bd26

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

tutorials/animation/playing_videos.rst

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ To implement the chroma key effect, follow these steps:
268268

269269
2. In the "ChromaKeyShader.gdshader" file, write the custom shader code as shown below:
270270

271-
.. code-block:: gd
271+
.. code-block:: glsl
272272
273273
shader_type canvas_item;
274274
@@ -311,25 +311,64 @@ UI Controls
311311

312312
To allow users to manipulate the chroma key effect in real-time, we created sliders in the `Control` node. The `Control` node's script contains the following functions:
313313

314-
.. code-block:: gd
314+
.. tabs::
315+
.. code-tab:: gdscript
315316

316-
extends Control
317+
extends Control
317318

318-
func _on_color_picker_button_color_changed(color):
319-
# Update the "chroma_key_color" shader parameter of the VideoStreamPlayer's material
320-
$VideoStreamPlayer.material.set("shader_parameter/chroma_key_color", color)
319+
func _on_color_picker_button_color_changed(color):
320+
# Update the "chroma_key_color" shader parameter of the VideoStreamPlayer's material.
321+
$VideoStreamPlayer.material.set("shader_parameter/chroma_key_color", color)
321322

322-
func _on_h_slider_value_changed(value):
323-
# Update the "pickup_range" shader parameter of the VideoStreamPlayer's material
324-
$VideoStreamPlayer.material.set("shader_parameter/pickup_range", value)
323+
func _on_h_slider_value_changed(value):
324+
# Update the "pickup_range" shader parameter of the VideoStreamPlayer's material.
325+
$VideoStreamPlayer.material.set("shader_parameter/pickup_range", value)
325326

326-
func _on_h_slider_2_value_changed(value):
327-
# Update the "fade_amount" shader parameter of the VideoStreamPlayer's material
328-
$VideoStreamPlayer.material.set("shader_parameter/fade_amount", value)
327+
func _on_h_slider_2_value_changed(value):
328+
# Update the "fade_amount" shader parameter of the VideoStreamPlayer's material.
329+
$VideoStreamPlayer.material.set("shader_parameter/fade_amount", value)
329330

330331
func _on_video_stream_player_finished():
331-
# Restart the video playback when it's finished
332-
$VideoStreamPlayer.play()
332+
# Restart the video playback when it's finished.
333+
$VideoStreamPlayer.play()
334+
335+
.. code-tab:: csharp
336+
337+
using Godot;
338+
339+
public partial class MyControl : Control
340+
{
341+
private VideoStreamPlayer _videoStreamPlayer;
342+
343+
public override void _Ready()
344+
{
345+
_videoStreamPlayer = GetNode<VideoStreamPlayer>("VideoStreamPlayer");
346+
}
347+
348+
private void OnColorPickerButtonColorChanged(Color color)
349+
{
350+
// Update the "chroma_key_color" shader parameter of the VideoStreamPlayer's material.
351+
_videoStreamPlayer.Material.Set("shader_parameter/chroma_key_color", color);
352+
}
353+
354+
private void OnHSliderValueChanged(double value)
355+
{
356+
// Update the "pickup_range" shader parameter of the VideoStreamPlayer's material.
357+
_videoStreamPlayer.Material.Set("shader_parameter/pickup_range", value);
358+
}
359+
360+
private void OnHSlider2ValueChanged(double value)
361+
{
362+
// Update the "fade_amount" shader parameter of the VideoStreamPlayer's material.
363+
_videoStreamPlayer.Material.Set("shader_parameter/fade_amount", value);
364+
}
365+
366+
private void OnVideoStreamPlayerFinished()
367+
{
368+
// Restart the video playback when it's finished.
369+
_videoStreamPlayer.Play();
370+
}
371+
}
333372

334373
also make sure that the range of the sliders are appropriate, our settings are :
335374

0 commit comments

Comments
 (0)