• Runtimes
  • Exporting frame animations with offset information

  • Đã chỉnh sửa
Related Discussions
...

Hey folks,

I'm currently exporting animations with the png Export option, using an atlas with stripped whitespaces. Because of that, single frames differ in width and hight. In Unity3D I want to render every frame simply with a rectangular mesh instead of using the more complex "bones"-mesh.

Now when it comes to poses like leaning forward (let's say to the right), the character takes more space on the right than it does on the left so the frame-images' center is offsetted from spines center.

Now it seems like I can't export the information of the correct offset of each frame-image so when I create my rectangular meshes that render a single frame, the character is offsetted every frame.

Can you guys help me out?

I'd like to make an export setting for this, but probably won't get to it for a while. 🙁 As a workaround, you can use a large transparent image to cause the image frames that are exported to all be the same size. The image needs to be as large or larger than any of the animations, in each direction (or at least the left and top or bottom sides, depending on if you use y-up or y-down at runtime). Since you are trimming whitespace this won't add any size to your images. Once all your frames are the same size, the 0,0 position in Spine (the axis lines) will be the same in every exported image and you then know where to draw at runtime. Make sense?

Here's an (extreme) example: create a transparent image that is 1000x1000. Place it so the upper right corner is at 0,0 in Spine. Now all your exported animation frame images will be at least 1000x1000 (probably more since your character is likely above and to the right of 0,0). In each frame image, you know that 1000 pixels from the bottom and 1000 pixels from the left corresponds to 0,0 in Spine, which is your reference point for positioning at runtime. Eg, if you want to put your character at 200,300 then draw the images at 200-1000,300-1000 = -800,-700.

Hmmm.. will think about that, hope I understood it right. But I think I'll export an atlas without stripping whitespaces so every frame has the same size and so the center is always the same. In Unity3D I then can create my own stripped atlas texture since I can calculate the center.

Each frame in an animation is exported the same size, using the maximal bounds throughout the animation. A reference point in one frame is the same in all other frames. Frames from different animations may be different sizes unless you use a trick with a transparent image as described.

Stripping whitespace is an optimization to save space in the atlas. When you go to draw, you offset the drawing location by the amount of whitespace stripped (this information is in the atlas). You don't gain anything (except slightly simpler drawing and a larger atlas) by not stripping whitespace.