瀏覽代碼

[godot] Closes #2832, SpineSprite.set_time_scale/get_time_scale

Mario Zechner 4 月之前
父節點
當前提交
2712cffc00

+ 1 - 1
spine-godot/spine_godot/SpineAnimationTrack.cpp

@@ -251,7 +251,7 @@ Ref<Animation> SpineAnimationTrack::create_animation(spine::Animation *animation
 	Ref<Animation> animation_ref;
 	INSTANTIATE(animation_ref);
 	String name;
-	name.parse_utf8(animation.getName().buffer());
+	name.parse_utf8(animation->getName().buffer());
 	animation_ref->set_name(name + (loop ? "" : "_looped"));
 #if VERSION_MAJOR > 3
 	// animation_ref->set_loop(!loop);

+ 1 - 2
spine-godot/spine_godot/SpineAtlasResource.cpp

@@ -62,10 +62,9 @@ class GodotSpineTextureLoader : public spine::TextureLoader {
 	Array *textures;
 	Array *normal_maps;
 	String normal_map_prefix;
-	bool is_importing;
 
 public:
-	GodotSpineTextureLoader(Array *_textures, Array *_normal_maps, const String &normal_map_prefix, bool is_importing) : textures(_textures), normal_maps(_normal_maps), normal_map_prefix(normal_map_prefix), is_importing(is_importing) {
+	GodotSpineTextureLoader(Array *_textures, Array *_normal_maps, const String &normal_map_prefix, bool is_importing) : textures(_textures), normal_maps(_normal_maps), normal_map_prefix(normal_map_prefix) {
 	}
 
 	static bool fix_path(String &path) {

+ 14 - 3
spine-godot/spine_godot/SpineSprite.cpp

@@ -434,6 +434,9 @@ void SpineSprite::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_screen_material", "material"), &SpineSprite::set_screen_material);
 	ClassDB::bind_method(D_METHOD("get_screen_material"), &SpineSprite::get_screen_material);
 
+	ClassDB::bind_method(D_METHOD("get_time_scale"), &SpineSprite::get_time_scale);
+	ClassDB::bind_method(D_METHOD("set_time_scale", "v"), &SpineSprite::set_time_scale);
+
 	ClassDB::bind_method(D_METHOD("set_debug_root", "v"), &SpineSprite::set_debug_root);
 	ClassDB::bind_method(D_METHOD("get_debug_root"), &SpineSprite::get_debug_root);
 	ClassDB::bind_method(D_METHOD("set_debug_root_color", "v"), &SpineSprite::set_debug_root_color);
@@ -509,7 +512,7 @@ void SpineSprite::_bind_methods() {
 	// Filled in in _get_property_list()
 }
 
-SpineSprite::SpineSprite() : update_mode(SpineConstant::UpdateMode_Process), preview_skin("Default"), preview_animation("-- Empty --"), preview_frame(false), preview_time(0), skeleton_clipper(nullptr), modified_bones(false) {
+SpineSprite::SpineSprite() : update_mode(SpineConstant::UpdateMode_Process), time_scale(1.0), preview_skin("Default"), preview_animation("-- Empty --"), preview_frame(false), preview_time(0), skeleton_clipper(nullptr), modified_bones(false) {
 	skeleton_clipper = new spine::SkeletonClipping();
 	auto statics = SpineSpriteStatics::instance();
 
@@ -817,12 +820,12 @@ void SpineSprite::update_skeleton(float delta) {
 		return;
 
 	emit_signal(SNAME("before_animation_state_update"), this);
-	animation_state->update(delta);
+	animation_state->update(delta * time_scale);
 	if (!is_visible_in_tree()) return;
 	emit_signal(SNAME("before_animation_state_apply"), this);
 	animation_state->apply(skeleton);
 	emit_signal(SNAME("before_world_transforms_change"), this);
-	skeleton->update(delta);
+	skeleton->update(delta * time_scale);
 	skeleton->update_world_transform(SpineConstant::Physics_Update);
 	modified_bones = false;
 	emit_signal(SNAME("world_transforms_changed"), this);
@@ -1401,6 +1404,14 @@ void SpineSprite::set_screen_material(Ref<Material> material) {
 	screen_material = material;
 }
 
+void SpineSprite::set_time_scale(float time_scale) {
+	this->time_scale = time_scale;
+}
+
+float SpineSprite::get_time_scale() {
+	return time_scale;
+}
+
 #ifndef SPINE_GODOT_EXTENSION
 // FIXME
 #ifdef TOOLS_ENABLED

+ 5 - 0
spine-godot/spine_godot/SpineSprite.h

@@ -141,6 +141,7 @@ protected:
 	Ref<SpineSkeleton> skeleton;
 	Ref<SpineAnimationState> animation_state;
 	SpineConstant::UpdateMode update_mode;
+	float time_scale;
 
 	String preview_skin;
 	String preview_animation;
@@ -230,6 +231,10 @@ public:
 
 	void set_screen_material(Ref<Material> material);
 
+	void set_time_scale(float time_scale);
+
+	float get_time_scale();
+
 	bool get_debug_root() { return debug_root; }
 
 	void set_debug_root(bool root) { debug_root = root; }