From 6fef444f0355bfa6a48ba792309259e65f68c388 Mon Sep 17 00:00:00 2001 From: badlogic Date: Thu, 21 Apr 2022 18:24:29 +0200 Subject: [PATCH] [godot] Add animation state listener example. --- spine-godot/example/examples/01-helloworld/helloworld.tscn | 4 +--- .../animation-state-listeners.gd | 7 ++++--- .../animation-state-listeners.tscn | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/spine-godot/example/examples/01-helloworld/helloworld.tscn b/spine-godot/example/examples/01-helloworld/helloworld.tscn index 8df3afcef..79c772efe 100644 --- a/spine-godot/example/examples/01-helloworld/helloworld.tscn +++ b/spine-godot/example/examples/01-helloworld/helloworld.tscn @@ -1,11 +1,9 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://examples/01-helloworld/spineboy-helloworld.gd" type="Script" id=1] -[ext_resource path="res://examples/02-animation-state-listeners/animation-state-listeners.gd" type="Script" id=2] [ext_resource path="res://assets/spineboy/spinebody-data-res.tres" type="SpineSkeletonDataResource" id=3] [node name="Node2D" type="Node2D"] -script = ExtResource( 2 ) [node name="Spineboy" type="SpineSprite" parent="."] position = Vector2( 496.207, 477.185 ) diff --git a/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.gd b/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.gd index 08ba4da08..3c497a102 100644 --- a/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.gd +++ b/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.gd @@ -1,5 +1,7 @@ extends Node2D +onready var footstep_audio: AudioStreamPlayer = $FootstepAudio + func _animation_started(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry): print("Animation started: " + track_entry.get_animation().get_name()) @@ -17,9 +19,8 @@ func _animation_disposed(sprite: SpineSprite, animation_state: SpineAnimationSta func _animation_event(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry, event: SpineEvent): print("Animation event: " + track_entry.get_animation().get_name() + ", " + event.get_data().get_event_name()) - if (event.get_data().get_event_name() == "footstep"): - var audio = $FootstepAudio - audio.play() + if (event.get_data().get_event_name() == "footstep"): + footstep_audio.play() func _ready(): var spineboy = $Spineboy diff --git a/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.tscn b/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.tscn index 0db3a0668..c9df7b7c2 100644 --- a/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.tscn +++ b/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.tscn @@ -7,10 +7,10 @@ [node name="Node2D" type="Node2D"] script = ExtResource( 1 ) -[node name="FootstepAudio" type="AudioStreamPlayer2D" parent="."] -stream = ExtResource( 3 ) - [node name="Spineboy" type="SpineSprite" parent="."] position = Vector2( 473, 487 ) scale = Vector2( 0.575051, 0.575051 ) skeleton_data_res = ExtResource( 2 ) + +[node name="FootstepAudio" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 3 )