Bläddra i källkod

[godot] Add animation state listener example.

badlogic 3 år sedan
förälder
incheckning
6fef444f03

+ 1 - 3
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 )

+ 4 - 3
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

+ 3 - 3
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 )