فهرست منبع

[godot] Refactored examples, added listener example, fixed listener signal names.

badlogic 3 سال پیش
والد
کامیت
b06b06c7c2

BIN
spine-godot/example/assets/footstep.ogg


+ 15 - 0
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

+ 1 - 0
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 ) ]

+ 4 - 2
spine-godot/example/examples/helloworld/helloworld.tscn → 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 )

+ 0 - 0
spine-godot/example/examples/helloworld/spineboy-helloworld.gd → spine-godot/example/examples/01-helloworld/spineboy-helloworld.gd


+ 37 - 0
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

+ 16 - 0
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 )

+ 0 - 0
spine-godot/example/examples/mix-and-match/mix-and-match.gd → spine-godot/example/examples/03-mix-and-match/mix-and-match.gd


+ 1 - 1
spine-godot/example/examples/mix-and-match/mix-and-match.tscn → 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"]
 

+ 1 - 1
spine-godot/example/examples/simple-input/simple-input.tscn → 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"]
 

+ 0 - 0
spine-godot/example/examples/simple-input/spineboy-simple-input.gd → spine-godot/example/examples/04-simple-input/spineboy-simple-input.gd


+ 1 - 1
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"
 

+ 25 - 25
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;
 	}
 }