/
PGStudio
/
DiplomaProject
Обзор
Документация
Войти
/
PGStudio
/
DiplomaProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/DisplayBackgrounds.gd
58 строк
2 KB
PGStudio
first_commit
21 июн 2026, 21:56
21 июн 2026, 21:56
69ac2dc
Код
Авторство
О чём код?
extends Node2D # INITIALIZATION @onready var CurrentSubViewport: SubViewport = $SubViewport const SpriteForVisualNovel = preload("res://scripts/SpriteForVisualNovel.gd") var time_animation: float = 2.0 class Background: var sprite: SpriteForVisualNovel.SpriteVN var current_background_name: String = "" var backgrounds: Dictionary[String, Background] # BASE FUNSTIONS func _ready() -> void: pass func _process(_delta: float) -> void: for name_background in backgrounds: var background: Background = backgrounds[name_background] background.sprite.update() # PUBLIC FUNSTIONS func add_background(background: PackedScene, background_name: String) -> void: var new_background: Background = Background.new() new_background.sprite = SpriteForVisualNovel.SpriteVN.new() new_background.sprite.set_sprite(background.instantiate(), CurrentSubViewport) CurrentSubViewport.size.y = max(CurrentSubViewport.size.y, new_background.sprite.get_size().y) CurrentSubViewport.size.x = int(float(CurrentSubViewport.size.y) * 4.0 / 3.0) if backgrounds.get(background_name) != null: print("Background \"%s\" is already exists! This background will be replaced!" % background_name) backgrounds.erase(background_name) backgrounds[background_name] = new_background func set_background(background_name: String) -> void: var target_position: Vector2 var target_scale: Vector2 = Vector2.ONE var target_alpha: float = 1.0 var target_time: float = time_animation if backgrounds.has(current_background_name): backgrounds[current_background_name].sprite.set_target(target_position, target_scale, 0.0, 0.0, target_time) current_background_name = background_name if backgrounds.has(background_name): backgrounds[background_name].sprite.set_target(target_position, target_scale, target_alpha, 0.0, target_time) func skip_animation() -> void: for name_background in backgrounds: var background: Background = backgrounds[name_background] background.sprite.skip_animation() func get_size() -> Vector2: return Vector2(CurrentSubViewport.size) func get_aspect() -> float: return CurrentSubViewport.size.aspect()