diff --git a/spine-godot/example/assets/footstep.ogg b/spine-godot/example/assets/footstep.ogg new file mode 100644 index 000000000..0e1468d8c Binary files /dev/null and b/spine-godot/example/assets/footstep.ogg differ diff --git a/spine-godot/example/assets/footstep.ogg.import b/spine-godot/example/assets/footstep.ogg.import new file mode 100644 index 000000000..0f8c88124 --- /dev/null +++ b/spine-godot/example/assets/footstep.ogg.import @@ -0,0 +1,15 @@ +[remap] + +importer="ogg_vorbis" +type="AudioStreamOGGVorbis" +path="res://.import/footstep.ogg-789c3f1e3c4e0ca3bebcb13f1160f623.oggstr" + +[deps] + +source_file="res://assets/footstep.ogg" +dest_files=[ "res://.import/footstep.ogg-789c3f1e3c4e0ca3bebcb13f1160f623.oggstr" ] + +[params] + +loop=true +loop_offset=0 diff --git a/spine-godot/example/assets/spineboy/spinebody-data-res.tres b/spine-godot/example/assets/spineboy/spinebody-data-res.tres index a6566b79c..5ba572eda 100644 --- a/spine-godot/example/assets/spineboy/spinebody-data-res.tres +++ b/spine-godot/example/assets/spineboy/spinebody-data-res.tres @@ -16,4 +16,5 @@ mix = 0.2 [resource] atlas_res = ExtResource( 1 ) skeleton_file_res = ExtResource( 2 ) +default_mix = 0.2 animation_mixes = [ SubResource( 1 ), SubResource( 2 ) ] diff --git a/spine-godot/example/examples/helloworld/helloworld.tscn b/spine-godot/example/examples/01-helloworld/helloworld.tscn similarity index 55% rename from spine-godot/example/examples/helloworld/helloworld.tscn rename to spine-godot/example/examples/01-helloworld/helloworld.tscn index 65eb6e9cd..8df3afcef 100644 --- a/spine-godot/example/examples/helloworld/helloworld.tscn +++ b/spine-godot/example/examples/01-helloworld/helloworld.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] -[ext_resource path="res://examples/helloworld/spineboy-helloworld.gd" type="Script" id=1] +[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/helloworld/spineboy-helloworld.gd b/spine-godot/example/examples/01-helloworld/spineboy-helloworld.gd similarity index 100% rename from spine-godot/example/examples/helloworld/spineboy-helloworld.gd rename to spine-godot/example/examples/01-helloworld/spineboy-helloworld.gd 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 new file mode 100644 index 000000000..08ba4da08 --- /dev/null +++ b/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.gd @@ -0,0 +1,37 @@ +extends Node2D + +func _animation_started(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry): + print("Animation started: " + track_entry.get_animation().get_name()) + +func _animation_interrupted(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry): + print("Animation interrupted: " + track_entry.get_animation().get_name()) + +func _animation_ended(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry): + print("Animation ended: " + track_entry.get_animation().get_name()) + +func _animation_completed(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry): + print("Animation completed: " + track_entry.get_animation().get_name()) + +func _animation_disposed(sprite: SpineSprite, animation_state: SpineAnimationState, track_entry: SpineTrackEntry): + print("Animation disposed: " + track_entry.get_animation().get_name()) + +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() + +func _ready(): + var spineboy = $Spineboy + var animation_state = spineboy.get_animation_state() + animation_state.set_animation("jump", false, 0) + animation_state.add_animation("walk", 0, true, 0) + animation_state.add_animation("run", 2, true, 0) + + spineboy.connect("animation_started", self, "_animation_started") + spineboy.connect("animation_interrupted", self, "_animation_interrupted") + spineboy.connect("animation_ended", self, "_animation_ended") + spineboy.connect("animation_completed", self, "_animation_completed") + spineboy.connect("animation_disposed", self, "_animation_disposed") + spineboy.connect("animation_event", self, "_animation_event") + pass 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 new file mode 100644 index 000000000..0db3a0668 --- /dev/null +++ b/spine-godot/example/examples/02-animation-state-listeners/animation-state-listeners.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://examples/02-animation-state-listeners/animation-state-listeners.gd" type="Script" id=1] +[ext_resource path="res://assets/spineboy/spinebody-data-res.tres" type="SpineSkeletonDataResource" id=2] +[ext_resource path="res://assets/footstep.ogg" type="AudioStream" id=3] + +[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 ) diff --git a/spine-godot/example/examples/mix-and-match/mix-and-match.gd b/spine-godot/example/examples/03-mix-and-match/mix-and-match.gd similarity index 100% rename from spine-godot/example/examples/mix-and-match/mix-and-match.gd rename to spine-godot/example/examples/03-mix-and-match/mix-and-match.gd diff --git a/spine-godot/example/examples/mix-and-match/mix-and-match.tscn b/spine-godot/example/examples/03-mix-and-match/mix-and-match.tscn similarity index 80% rename from spine-godot/example/examples/mix-and-match/mix-and-match.tscn rename to spine-godot/example/examples/03-mix-and-match/mix-and-match.tscn index a3c6865c3..c3f9d25aa 100644 --- a/spine-godot/example/examples/mix-and-match/mix-and-match.tscn +++ b/spine-godot/example/examples/03-mix-and-match/mix-and-match.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=2] [ext_resource path="res://assets/mix-and-match/mix-and-match-data.tres" type="SpineSkeletonDataResource" id=1] -[ext_resource path="res://examples/mix-and-match/mix-and-match.gd" type="Script" id=2] +[ext_resource path="res://examples/03-mix-and-match/mix-and-match.gd" type="Script" id=2] [node name="Node2D" type="Node2D"] diff --git a/spine-godot/example/examples/simple-input/simple-input.tscn b/spine-godot/example/examples/04-simple-input/simple-input.tscn similarity index 79% rename from spine-godot/example/examples/simple-input/simple-input.tscn rename to spine-godot/example/examples/04-simple-input/simple-input.tscn index 158909975..ad85e9dba 100644 --- a/spine-godot/example/examples/simple-input/simple-input.tscn +++ b/spine-godot/example/examples/04-simple-input/simple-input.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=2] [ext_resource path="res://assets/spineboy/spinebody-data-res.tres" type="SpineSkeletonDataResource" id=1] -[ext_resource path="res://examples/simple-input/spineboy-simple-input.gd" type="Script" id=2] +[ext_resource path="res://examples/04-simple-input/spineboy-simple-input.gd" type="Script" id=2] [node name="Node2D" type="Node2D"] diff --git a/spine-godot/example/examples/simple-input/spineboy-simple-input.gd b/spine-godot/example/examples/04-simple-input/spineboy-simple-input.gd similarity index 100% rename from spine-godot/example/examples/simple-input/spineboy-simple-input.gd rename to spine-godot/example/examples/04-simple-input/spineboy-simple-input.gd diff --git a/spine-godot/example/project.godot b/spine-godot/example/project.godot index 464c70e05..b52e4a317 100644 --- a/spine-godot/example/project.godot +++ b/spine-godot/example/project.godot @@ -11,7 +11,7 @@ config_version=4 [application] config/name="spine-godot-examples" -run/main_scene="res://examples/simple-input/simple-input.tscn" +run/main_scene="res://examples/01-helloworld/helloworld.tscn" run/low_processor_mode=true config/icon="res://icon.png" diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index 1d5e381ec..a762a8a4b 100644 --- a/spine-godot/spine_godot/SpineSprite.cpp +++ b/spine-godot/spine_godot/SpineSprite.cpp @@ -53,13 +53,13 @@ void SpineSprite::_bind_methods() { ClassDB::bind_method(D_METHOD("update_skeleton", "delta"), &SpineSprite::update_skeleton); - ADD_SIGNAL(MethodInfo("animation_start", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); - ADD_SIGNAL(MethodInfo("animation_interrupt", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); - ADD_SIGNAL(MethodInfo("animation_end", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); - ADD_SIGNAL(MethodInfo("animation_complete", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); - ADD_SIGNAL(MethodInfo("animation_dispose", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); - ADD_SIGNAL(MethodInfo("animation_event", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); - ADD_SIGNAL(MethodInfo("world_transforms_changed")); + ADD_SIGNAL(MethodInfo("animation_started", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"), PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"))); + ADD_SIGNAL(MethodInfo("animation_interrupted", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"), PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"))); + ADD_SIGNAL(MethodInfo("animation_ended", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"), PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"))); + ADD_SIGNAL(MethodInfo("animation_completed", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"), PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"))); + ADD_SIGNAL(MethodInfo("animation_disposed", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"), PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"))); + ADD_SIGNAL(MethodInfo("animation_event", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"), PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); + ADD_SIGNAL(MethodInfo("world_transforms_changed", PropertyInfo(Variant::OBJECT, "spine_sprite", PROPERTY_HINT_TYPE_STRING, "SpineSprite"))); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_data_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonDataResource"), "set_skeleton_data_res", "get_skeleton_data_res"); ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Process,Physics,Manual"), "set_update_mode", "get_update_mode"); @@ -511,24 +511,24 @@ void SpineSprite::callback(spine::AnimationState *state, spine::EventType type, } switch (type) { - case spine::EventType_Start: { - emit_signal("animation_start", animation_state, entry_ref, event_ref); - } break; - case spine::EventType_Interrupt: { - emit_signal("animation_interrupt", animation_state, entry_ref, event_ref); - } break; - case spine::EventType_End: { - emit_signal("animation_end", animation_state, entry_ref, event_ref); - } break; - case spine::EventType_Complete: { - emit_signal("animation_complete", animation_state, entry_ref, event_ref); - } break; - case spine::EventType_Dispose: { - emit_signal("animation_dispose", animation_state, entry_ref, event_ref); - } break; - case spine::EventType_Event: { - emit_signal("animation_event", animation_state, entry_ref, event_ref); - } break; + case spine::EventType_Start: + emit_signal("animation_started", this, animation_state, entry_ref); + break; + case spine::EventType_Interrupt: + emit_signal("animation_interrupted", this, animation_state, entry_ref); + break; + case spine::EventType_End: + emit_signal("animation_ended", this, animation_state, entry_ref); + break; + case spine::EventType_Complete: + emit_signal("animation_completed", this, animation_state, entry_ref); + break; + case spine::EventType_Dispose: + emit_signal("animation_disposed", this, animation_state, entry_ref, event_ref); + break; + case spine::EventType_Event: + emit_signal("animation_event", this, animation_state, entry_ref, event_ref); + break; } }