From 1bc8382ef5239c6a7622098874b9177ab147d889 Mon Sep 17 00:00:00 2001 From: Clevertop <41929769+Clevertop@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:43:30 +1000 Subject: [PATCH] image gallery --- widgets/imageGallery.tscn | 34 ++++++++++++++++++++++++++++++++++ widgets/image_gallery.gd | 30 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 widgets/imageGallery.tscn create mode 100644 widgets/image_gallery.gd diff --git a/widgets/imageGallery.tscn b/widgets/imageGallery.tscn new file mode 100644 index 0000000..ed3c614 --- /dev/null +++ b/widgets/imageGallery.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=4 format=3 uid="uid://btfa7ec7kchhv"] + +[ext_resource type="Script" path="res://widgets/image_gallery.gd" id="1_f7mmh"] + +[sub_resource type="Gradient" id="Gradient_2nnog"] +offsets = PackedFloat32Array(0, 0.446154, 0.54359, 0.758974) +colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0.14, 0.14, 0.14, 1) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_7b30j"] +gradient = SubResource("Gradient_2nnog") +fill_from = Vector2(0, 1) + +[node name="ImageGallery" type="Control" node_paths=PackedStringArray("textureRect")] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +script = ExtResource("1_f7mmh") +textureRect = NodePath("TextureRect") + +[node name="TextureRect" type="TextureRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = SubResource("GradientTexture2D_7b30j") +expand_mode = 1 +stretch_mode = 5 diff --git a/widgets/image_gallery.gd b/widgets/image_gallery.gd new file mode 100644 index 0000000..14ffe5a --- /dev/null +++ b/widgets/image_gallery.gd @@ -0,0 +1,30 @@ +extends Control + +@export var textureRect : TextureRect +@export var images : Array[Texture2D] +@export var image_time : float = 2.5 + +var current_image : int = 0 +var num_images : int +var remainingTime : float + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + num_images = images.size() + switch_to(0) + remainingTime = image_time + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + remainingTime -= delta + if (remainingTime <= 0): + current_image += 1 + if(current_image>num_images-1): + current_image = 0 + switch_to(current_image) + remainingTime = image_time + +func switch_to(id : int): + textureRect.texture = images[id]