diff --git a/spine-godot/example/examples/05-mouse-following/mouse-following.gd b/spine-godot/example/examples/05-mouse-following/mouse-following.gd index 471eab156..a62e61857 100644 --- a/spine-godot/example/examples/05-mouse-following/mouse-following.gd +++ b/spine-godot/example/examples/05-mouse-following/mouse-following.gd @@ -1,11 +1,11 @@ extends Node2D onready var spineboy: SpineSprite = $Spineboy - -func _world_transforms_changed(_sprite): - spineboy.set_global_bone_transform("crosshair", Transform2D(0, get_viewport().get_mouse_position())) +onready var crosshair_bone: SpineBoneNode = $Spineboy/CrosshairBone func _ready(): spineboy.get_animation_state().set_animation("walk", true, 0) spineboy.get_animation_state().set_animation("aim", true, 1) - spineboy.connect("world_transforms_changed", self, "_world_transforms_changed") + +func _process(_delta): + crosshair_bone.global_position = get_viewport().get_mouse_position() diff --git a/spine-godot/example/examples/05-mouse-following/mouse-following.tscn b/spine-godot/example/examples/05-mouse-following/mouse-following.tscn index e4e08a03a..d199ac64e 100644 --- a/spine-godot/example/examples/05-mouse-following/mouse-following.tscn +++ b/spine-godot/example/examples/05-mouse-following/mouse-following.tscn @@ -13,3 +13,9 @@ skeleton_data_res = ExtResource( 2 ) preview_animation = "-- Empty --" preview_frame = false preview_time = 0.0 + +[node name="CrosshairBone" type="SpineBoneNode" parent="Spineboy"] +position = Vector2( 302.333, -569.714 ) +rotation = -0.000872665 +bone_name = "crosshair" +bone_mode = 1 diff --git a/spine-godot/example/examples/06-bone-following/bone-following.gd b/spine-godot/example/examples/06-bone-following/bone-following.gd index a3415c511..caa900ac7 100644 --- a/spine-godot/example/examples/06-bone-following/bone-following.gd +++ b/spine-godot/example/examples/06-bone-following/bone-following.gd @@ -1,11 +1,6 @@ extends Node2D -onready var spineboy: SpineSprite = $Spineboy -onready var sprite: Sprite = $Spineboy/Sprite - -func _world_transforms_changed(_sprite): - sprite.global_transform = spineboy.get_global_bone_transform("gun-tip") - func _ready(): + var spineboy: SpineSprite = $Spineboy spineboy.get_animation_state().set_animation("walk", true, 0) spineboy.connect("world_transforms_changed", self, "_world_transforms_changed") diff --git a/spine-godot/example/examples/06-bone-following/bone-following.tscn b/spine-godot/example/examples/06-bone-following/bone-following.tscn index 8bdac4fdb..dd8226c67 100644 --- a/spine-godot/example/examples/06-bone-following/bone-following.tscn +++ b/spine-godot/example/examples/06-bone-following/bone-following.tscn @@ -11,7 +11,16 @@ script = ExtResource( 2 ) position = Vector2( 478, 483 ) scale = Vector2( 0.58461, 0.58461 ) skeleton_data_res = ExtResource( 1 ) +preview_animation = "" +preview_frame = false +preview_time = 0.0 -[node name="Sprite" type="Sprite" parent="Spineboy"] -position = Vector2( 20, 20 ) +[node name="GunTipBone" type="SpineBoneNode" parent="Spineboy"] +position = Vector2( 214.298, -162.047 ) +rotation = 0.713316 +scale = Vector2( 1, 1 ) +bone_name = "gun-tip" + +[node name="Sprite" type="Sprite" parent="Spineboy/GunTipBone"] +scale = Vector2( 1, 1 ) texture = ExtResource( 3 ) diff --git a/spine-godot/spine_godot/SpineBone.cpp b/spine-godot/spine_godot/SpineBone.cpp index f4ad04233..c83116978 100644 --- a/spine-godot/spine_godot/SpineBone.cpp +++ b/spine-godot/spine_godot/SpineBone.cpp @@ -481,7 +481,7 @@ void SpineBone::set_global_transform(Transform2D transform) { if (parent) { parent->worldToLocal(local_x, local_y, local_x, local_y); parent->worldToLocal(position.x + local_scale.x, position.y + local_scale.y, local_scale.x, local_scale.y); - local_scale.x -= local_x; + local_scale.x = (local_scale.x - local_x); local_scale.y = -(local_scale.y - local_y); local_rotation = 180 + bone->worldToLocalRotation(local_rotation); }