• Editor
  • Recent commits broke flipping?

Related Discussions
...

I'm having weird issues with flipping.
I have my character moving from the left to right of the screen.
When i do skeleton.setFlipX(true), the character is now moving from the right to left.
I expected it to still move in the same direction, just with the animation flipped.
I thought I was doing something wrong.

But then i fired up the SkeletonTest.java, the goblin is supposed to walk back and forth, but instead, he just walks to the right, and when hes supposed to turn around and walk to the left again, he instead keeps going off to the right.

This was not the case previously.
Did a recent commit change/break something?

Thanks.

I had a look at the commits, and it seems this is the cause for the problem


---

 spine-libgdx/src/com/esotericsoftware/spine/Bone.java 

---


diff 

---

git a/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/src/com/esotericsoftware/spine/Bone.java
index d057f25..80262c0 100644


---

 a/spine-libgdx/src/com/esotericsoftware/spine/Bone.java
+++ b/spine-libgdx/src/com/esotericsoftware/spine/Bone.java
@@ -73,8 +73,8 @@
 			worldScaleY = parent.worldScaleY * scaleY;
 			worldRotation = parent.worldRotation + rotation;
 		} else {
-			worldX = x;
-			worldY = y;
+			worldX = flipX ? -x : x;
+			worldY = flipY ? -y : y;
 			worldScaleX = scaleX;
 			worldScaleY = scaleY;
 			worldRotation = rotation;

I've been setting the positions of the skeletons by using Skeleton.getRootBone.setX/Y(float). Is this the correct way?
Previously, setFlipX/Y would flip with respect to the root bone. Now it is flipping around the word axis.
So if I want to position the skeleton at say (100,0), with flipX enabled, it will appear at (-100,0), which seems a wrong to me.

It looks like the change was made in reponse to this thread about not being able to 'flip the root bone'
viewtopic.php?f=3&t=608

However, since the root bone is basically the origin of the skeleton, everything should flip around the root bone. I feel like 'flipping the root bone' doesn't really make sense. What are you flipping the root bone around? If you flip the root bone around the origin of the world (as it currently is), you mess up the positioning of the skeleton (as shown by SkeletonTest being broken). The OP's suggestion of creating a new bone, parenting all the bones to that, and have the new bone flip around the root bone is correct.

Yep, I agree. I will fix! Edit: fixed, thanks!

Hi,

My thread was not about not being able to flip the root bone, but about flipping the skeleton does not affect the root bone. Is the root bone not part of the skeleton? Why would flipping a skeleton (not a single bone - you cannot flip the specific bones with current functionality) not a affect one of it's bones?

I don't think it's a good practice to be moving a skeleton by it's root bone rather than having a separate position vector which the root bone would be offset by in the render code. Then again this change is not a deal breaker for me to have that extra useless bone layer on in all of the skeletons, I just think it will cause more trouble than save.

So assuming this change, will we see a change in the Spine editor that will lock the root bone's position to 0,0 as per moving it will cause the object to be broken when it is flipped?

Thanks,
Jap

Looks to me like the root bone is just used for positioning.
It makes sense to me to flip around the root bone.

Flipping around the axis that is local to the skeleton could also be valid. However, it was implemented incorrectly, ie. it was flipping around the axis of the world, not the axis of the skeleton. Before the commit was reverted, position your skeleton anywhere except (0,0) and apply flip and you will see it doesn't appear where you expect.

I'm not sure what you mean by "Flipping around the axis that is local to the skeleton could also be valid". What would define such an axis? A skeleton has a global coordinate system and then a number of bones, which each have its own a coordinate system.

The root bone is indeed a bone in every sense. It is only special because it has no parent. A bone has its own coordinate system. It originates at the bone position and is rotated and scaled by the bone. Each child is defined in this coordinate system and so is affected by the scale, rotation, and translation of the parent. Since the root has no parent, it is uses the "global" coordinate system which is (typically) screen axis aligned and has no rotation and scale.

The question is: Do we define flipping the skeleton as flipping the global coordinate system or flipping the root bone? This decision affects how the skeleton is positioned at runtime.

Currently, in some runtimes the skeleton is placed by setting the root bone position, so flipping the skeleton by flipping the global coordinate system changes the position, which is not desired. The skeleton could have an x and y position which is added to the world positions of the bones. Leaving the root bone at 0,0 and then setting its position is just another way to do this.

In other runtimes something else is positioned, eg a scene graph node. In this case 0,0 is the position of the skeleton. This means the root bone does not need to be positioned to place the skeleton, so the root bone doesn't need to be at 0,0 and can be used for part of the skeleton. If the skeleton is flipped by flipping the root bone, the root bone position is not changed and so will be in the wrong place.

What is the reference point for a skeleton? 0,0 or the root bone position? It's an interesting decision since both approaches are valid. I'm leaning toward not using the root bone for position. This means 2 extra additions are needed to offset each bone's world position for rendering, but we will have one less bone transform, which is 10 multiplies, 5 additions, a cos, a sin, 3 ifs, a method call, and about 25 field accesses. What do you guys think?

When i say 'Flipping around the axis that is local to the skeleton', i meant, the axis that you see in the spine editor. IE, if you placed your root bone, 5 units to the right of the origin in spine editor, at run time it would flip around the point 5 units to the left of the root bone no matter where it was positioned. Before the revert it was flipping around the global axis. So even if your root bone was at x=5 in spine editor, if you then position it at x=1000 at runtime and flip, it would flip to x= -1000 where I expected it to flip to x=990.
I hope you get what I mean.

Either flipping as I described above, or flipping about the root bone makes the most sense to me. However others may think differently, and I'm not familiar with how other runtimes work and am not using scene graphs.

tl;dr
Basically, If i have a skeleton at x=1000, and I flip it, I want it to stay where it is and just face the other way. I don't want it to teleport to x=-1000 as well. However it's ultimately up to you or the majority how to deal with this.

I'm leaning toward not using the root bone for position.

Do you mean just giving the skeleton a position attribute?

I don't think I should have to understand all the nuances of the root bone to use spine. It sounds like the root bone also means too many things and has conflicting uses. Anytime I find something like this in my code I know I'm asking for trouble.

I think all the runtimes should support positioning a skeleton in the same way they all support positioning sprites or whatever objects they have in their engines. Its not really productive to have to understand the way spine does positioning so I can then position the skeleton where I want it to be. At that level the skeleton should just be another object not something that I have special understanding of. I also think you are asking for a support nightmare if everyone has to write their own "make the spine skeleton position correctly" in my game engine code. There will be an endless supply of forum posts asking why my skeleton is not positioned where I want it to be. And please don't get me wrong I know I can figure out how to do it no matter what you provide but you really probably know better than me how varied the spine user skillset is going to be.

For example, in Cocos2d, I should be able to set the position and anchorpoint of the AnimationNode just like I can any other node and the skeleton should work like I expect. So if I set the anchorpoint to 0.5,0.5 and then set the position of the AnimationNode to the middle of the screen the skeleton should be centered on the screen.

Barry escreveu

For example, in Cocos2d, I should be able to set the position and anchorpoint of the AnimationNode just like I can any other node and the skeleton should work like I expect. So if I set the anchorpoint to 0.5,0.5 and then set the position of the AnimationNode to the middle of the screen the skeleton should be centered on the screen.

Sort of. A skeleton doesn't have a (meaningful) center, since it is animating and (almost always) changing size. You need a reference point in the editor so when you place your character it is relative to that point. Eg, typically with a standing character you want the reference point between the feet. We are discussing whether this reference point should be 0,0 in global space or the root bone. There won't be any special nuances you have to deal with, have a little faith. :*

terryhau escreveu

When i say 'Flipping around the axis that is local to the skeleton', i meant, the axis that you see in the spine editor. IE, if you placed your root bone, 5 units to the right of the origin in spine editor, at run time it would flip around the point 5 units to the left of the root bone no matter where it was positioned.

The axes you see in the editor are 0,0 in global space. The root bone is positioned in global space, this is why flipping global space messes up where you have positioned the root bone.

Do you mean just giving the skeleton a position attribute?

Yes. I think this is the best way to handle it. The two options are not so different, but this option is slightly more efficient. It is basically what you described. Giving it a go right now.

20 dias depois

I finally have made these changes. Flip now flips the root bone around the origin. Use skeleton x/y to position your skeleton, not the root bone. It is no longer necessary to leave the root bone at 0,0 and unkeyed.

What is the origin now? The middle line in the editor or sth? Or is it calculated?

What's sth?

sth = something 🙂 Old habit. 🙂

The origin in Spine is 0,0. When you place the skeleton at x,y you are placing the origin in Spine at that position. So, use 0,0 in the editor as a reference point for positioning your skeleton at runtime.

OK. Thanks. That should make things easier.

hey quick question from a novice!! does this 'flipping' mean that i can take my skeleton with it's images and in effect have all the components mirrored to give the appearance that it's now facing in the opposite direction??

to give an example of how i'd love to use this. I have a character walking left-> right, they then encounter a collision object. On encountering this, they about turn. This then has the character facing right->left. I could then take this new flippeed position and either make the character walk in the opposite direction OR walk backwards.

Is my understanding correct??

cheers
jim

Yes, flipping changes rendering so everything is drawing facing the other way.

thanks nate i thought that was how it worked -perfect (again)

thanks
jim

btw - is it possible to test this out inside the GUI when creating an animation, or is this api runtime process only??