Last active
May 12, 2019 06:55
-
-
Save kane-thornwyrd/02cf51e483f6795616017e3958ec24d1 to your computer and use it in GitHub Desktop.
echoes for Godot 3.1 by Kane Thornwyrd under GPL v3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Sprite | |
class_name Echo | |
const SHIFT_TRANS = Tween.TRANS_SINE | |
const SHIFT_EASE = Tween.EASE_OUT | |
export var sprite_path: NodePath | |
export var gradient: Gradient | |
onready var echo_timer:Timer = $echo_timer | |
onready var alpha_tween:Tween = $alpha_tween | |
onready var echoing_sprite:Sprite = get_node(sprite_path) | |
onready var echoing_parent:Node2D = self.get_parent() | |
var duration:float | |
func echo_start(delay:float, duration:float) -> void: | |
self.duration = duration | |
# warning-ignore:return_value_discarded | |
echo_timer.connect("timeout", self, "echo") | |
echo_timer.start(delay) | |
func echo_stop() -> void: | |
echo_timer.stop() | |
func echo() -> void: | |
var echo = self.duplicate() | |
echo.position = echoing_parent.position | |
echo.texture = echoing_sprite.texture | |
echo.vframes = echoing_sprite.vframes | |
echo.hframes = echoing_sprite.hframes | |
echo.frame = echoing_sprite.frame | |
echo.scale = echoing_sprite.scale | |
echo.flip_h = echoing_sprite.flip_h | |
echo.flip_v = echoing_sprite.flip_v | |
# warning-ignore:return_value_discarded | |
alpha_tween.interpolate_property(echo, "modulate", gradient.get_color(0), gradient.get_color(gradient.get_point_count()-1), self.duration, SHIFT_TRANS, SHIFT_EASE) | |
# warning-ignore:return_value_discarded | |
alpha_tween.start() | |
echoing_parent.get_parent().add_child(echo) | |
var t = Timer.new() | |
t.set_wait_time(duration) | |
t.set_one_shot(true) | |
echo.add_child(t) | |
t.start() | |
yield(t, "timeout") | |
t.queue_free() | |
echo.queue_free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[gd_scene load_steps=2 format=2] | |
[ext_resource path="res://assets/effects/echo.gd" type="Script" id=1] | |
[node name="echo" type="Sprite"] | |
script = ExtResource( 1 ) | |
[node name="alpha_tween" type="Tween" parent="."] | |
[node name="echo_timer" type="Timer" parent="."] | |
wait_time = 0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment