[godot] Adds physics support to translating SpineBoneNodes

This commit makes it so that adding a SpineBoneNode as a child node to a
SpineSprite node, selecting "Drive", and then adjusting the X/Y of the
SpineBoneNode in Move mode will affect the Physics Constraints like a
rotation already does.
This commit is contained in:
Luke Ingram 2025-10-15 16:27:11 -04:00
parent 639a76b3fa
commit 5e6dace791

View File

@ -70,6 +70,7 @@ void SpineBoneNode::_notification(int what) {
#else
sprite->connect(SNAME("world_transforms_changed"), this, SNAME("_on_world_transforms_changed"));
#endif
set_notify_local_transform(bone_mode == SpineConstant::BoneMode_Drive);
update_transform(sprite);
#if VERSION_MAJOR == 3
_change_notify("transform/translation");
@ -97,6 +98,18 @@ void SpineBoneNode::_notification(int what) {
}
break;
}
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (bone_mode == SpineConstant::BoneMode_Drive && enabled) {
SpineSprite *sprite = find_parent_sprite();
if (sprite) {
Ref<SpineBone> bone = find_bone();
if (bone.is_valid()) {
bone->set_global_transform(get_global_transform());
}
}
}
break;
}
case NOTIFICATION_DRAW: {
draw();
break;
@ -247,6 +260,7 @@ SpineConstant::BoneMode SpineBoneNode::get_bone_mode() {
void SpineBoneNode::set_bone_mode(SpineConstant::BoneMode _bone_mode) {
if (bone_mode != _bone_mode) {
bone_mode = _bone_mode;
set_notify_local_transform(bone_mode == SpineConstant::BoneMode_Drive);
SpineSprite *sprite = find_parent_sprite();
init_transform(sprite);
}