Spine--using animations in programs

Source: Internet
Author: User

The movement of characters in the game, running, attacking and other actions are essential, the way to implement them is generally used frame animation or skeletal animation.

The difference between frame animations and skeletal animations is that each frame of a frame animation is a snapshot of a character-specific pose, and the fluency and smoothness of the animation depend on the number of frames. Skeletal animation is the animation that binds parts of the body part of a character to a "bone" that is connected by a root, by controlling the position of the bones, the direction of rotation, and the zooming out.




Skeletal animation requires more processor performance than traditional frame-by-frames animations, but it also has more advantages, such as:

  • Less art resources: Bone animation Resources is a small part of the role of the parts (such as: Head, hands, arms, waist, etc.), art no longer need to provide a complete picture of each frame, which undoubtedly save the size of resources, can save you more human and material better into the game development.
  • Smaller volume: Frame animations need to provide each frame of the picture. Skeletal animation only requires a small amount of picture resources, and the skeleton animation data stored in a JSON file (mentioned later), it occupies a very small space, and can provide your game unique animation.
  • Better fluency: Skeletal animations use the difference algorithm to calculate intermediate frames, which will keep your animations flowing smoothly.
  • Equip attachments: Picture bindings animate on bones. If you need to be able to easily change the character of the equipment to meet different needs. Even change the character's appearance to achieve the effect of animation reuse.
  • Different animations can be mixed: different skeletal animations can be combined. For example a character can turn the head, shoot and also walk at the same time.
  • Program Animation: You can control the bones through code, such as can be achieved following the mouse shooting, gaze at the enemy, or uphill when the body tilt and other effects.
Skeletal Animation editor--spine

Spine is a game-oriented 2D skeletal animation editing tool that has a good UI design and complete functionality, and is a more mature skeleton animation editor. Spine is designed to provide a more efficient and streamlined workflow to create the animations needed for the game.

There are two main steps to creating a skeletal animation using spine:

  1. In Setup mode, assemble the character parts and bind the bones to them;
  2. In animate mode, animations are created based on the bound bones.

Below is a brief introduction to the next steps, more details please see the official website Tutorial: Spine Quick Start Tutorial.

1) in Setup mode, check the images property, import the desired picture resource folder, where the path name and resource name can not appear in Chinese, otherwise cannot parse;

2) Drag the picture under the images to the scene, assemble the characters (place each body part together), and adjust the order of the layers of the picture by the draw order property;

3) Create bones, and bind the pictures to the bones, pay attention to the parent-child relationship of each bone.

4) switch to animate mode, select the bone you want to "move", rotate it, move it, zoom, and so on, remember to hit the keyframe after each change.

5) Locate the texture Packer item in the menu bar, package the character texture, and the resource file suffix is Atlas (not the Cocos2d-x common plist). After packaging, two files will be generated, namely PNG and Atlas.



6) Export the animation file JSON.

Use of spine animations

In cocos2d-x programs, the spine animation first needs to include spine related header files.

#include <spine/spine-cocos2dx.h>"spine/spine.h"using  namespace spine;

The common methods are as follows:

Creates an spine animation object that imports animation files and resource files.

New Skeletonanimation ("enemy.json""enemy.atlas");

Skeletal animation is often more than one animation, for example: when the character needs to walk, set the play animation to walk, when the attack, set to play the animation as an attack. The following method sets the current playback animation, where the parameter false indicates that playback does not loop, and true indicates looping.

Skeletonnode->setanimation (0"walk"true);

The Setanimation method can play only one animation, so when you want to play a different animation continuously, you need to use the Addanimation method, which can play different animations one by one.

Skeletonnode->addanimation (0"walk"true); skeletonnode ->addanimation (0"attack"false);

For the general situation, the animation of the switch requires two animation can be fully connected, otherwise there will be jumping sense, this for the fine arts, and spine added a mix of animation function to solve the problem. So that does not require two animation can be fully connected, such as the above walk and attack animation, is not cohesive, directly according to the above method to play, will appear jumping, but added a mix, it looks very natural. Even if you slow down 10 times times the speed of observation, it is perfect. This feature is not achievable in sequence frame animations, and is a feature that most embodies the value of spine.

Skeletonnode->setmix ("walk""attack"0.2f) ; Skeletonnode->setmix ("attack""walk" 0.4f);

Setting the playback speed of an animation can be achieved by setting its timescale value.

0.6f;

Sets whether the bone is displayed by setting Debugbones,true for display, false to hide.

true;

Example: Create an animation of a player walking and attacking, and loop it back.

Auto Skeletonnode =NewSkeletonanimation ("Enemy.json","Enemy.atlas"); Skeletonnode->setmix ("Walk","Attack",0.2f); Skeletonnode->setmix ("Attack","Walk",0.4f); Skeletonnode->setanimation (0,"Walk",false); Skeletonnode->setanimation (0,"attact",false); Skeletonnode->addanimation (0,"Walk",false); Skeletonnode->addanimation (0,"attact",true); Skeletonnode->debugbones =true; Size windowsize= Director::getinstance ()getwinsize (); Skeletonnode->setposition (Point (Windowsize.width/2, Windowsize.height/2) ); AddChild (Skeletonnode);



Spine--using animations in programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.