boagz57

For my 2d fighting game I'm using the spine-c runtime libraries along with spine and I'm facing my ai skeleton in the opposite direction by flipping the skeleton's 'scaleX' property like so:
ai->worldPos = { (stage->info.size.width / 2.0f) + 300.0f, (stage->info.size.height / 2.0f) - 900.0f };
ai->skeleton->scaleX = -0.6f; // Flip ai fighter to start
ai->skeleton->scaleY = 0.6f;
However, later I found that when computing the world vertices of that same skeleton's bounding box for collision detection using 'spVertexAttachment_computeWorldVertices', the world vertices the function produced were in opposite order of my other player skeleton for which it's scaleX was not flipped. So calling computeWorldVertices for ai skeleton produced vertices like:

Vert1- TopRight
Vert2 - TopLeft
Vert 3 - BottomLeft
Vert 4 - BottomRight

and calling that for my other skeleton produced for which the scaleX was not flipped produced:

Vert1 TopLeft
Vert2 TopRight
Vert3 BottomRight
Vert4 BottomLeft

Needless to say this was causing some bugs in my program. My questions are:

1.) Is flipping the scaleX (or Y) the proper way to flip a skeleton in spine now that flipX and flipY seem to be deprecated?

if so

2.) Would the above issue be considered a bug or do I need to shift my understanding of the library a bit and use some other helper functions for this and other tasks?
boagz57
  • Bài viết: 26

Nate

Skeleton scale is the right way to flip the skeleton (and will flip even bones that have inherit scale disabled). It is more powerful that flipX/Y was. It can cause slight differences, as you found with bounding box winding. You could check if the scaleX sign is not the same as scaleY and reverse the winding.
Hình đại diện của thành viên
Nate

Nate
  • Bài viết: 9834

boagz57

Ya, I'll definitely implement some code to check winding. Are there any other slight discrepancies due to negative scale that you are aware of that I should keep a look out for?
boagz57
  • Bài viết: 26

Nate

All I can think of is the winding. Note it affects region and mesh rendering in the same way, so if you have back face culling enabled, everything will disappear when flipped.
Hình đại diện của thành viên
Nate

Nate
  • Bài viết: 9834

boagz57

Alright perfect, thanks for the response.
boagz57
  • Bài viết: 26

truelion07

I am trying this out, it works, spine character flips left and right:

skeleton.scaleX = 1;//right
skeleton.scaleX = -1; //left

is this the right way?
truelion07
  • Bài viết: 16

Nate

Yep!
Hình đại diện của thành viên
Nate

Nate
  • Bài viết: 9834


Quay về Runtimes