[godot] Add animation state listener example.

This commit is contained in:
badlogic 2022-04-21 18:24:29 +02:00
parent b06b06c7c2
commit 6fef444f03
3 changed files with 8 additions and 9 deletions

View File

@ -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 )

View File

@ -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

View File

@ -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 )