Cubism SDK‎ > ‎Live2D Library‎ > ‎Motion Manager‎ > ‎

Motion

Flow to play Motion

1. Motion class
a. Create instances (load mtn files)
b. Setting

2. Motion management class
a. Create instances
b. Play the motion
c. Update the Motion Parameter of the model
d. Stop the motion



1-a. Create a motion instances (load mtn files)

A class of Live2DMotion is used to play motion.
Data used as motion is a motion file with ".mtn" as an extension.
The
loadMotion function is used to load the .mtn motion data.
There are two ways provided to load it from the file pass or from the byte array for most platforms.

You can load it by choosing one of those below;


Live2DMotion* motion = Live2DMotion::loadMotion( path );

or

Live2DMotion* motion = Live2DMotion::loadMotion( byteArray, size );




1-b. Motion settings

You can make settings of the items below;
You can play a motion even if you do not make settings of them.

* Length of fading in when a motion is started.
You can make settings of it with the setFadeIn function, and get it with the getFadeIn function.
Specify the length of fading in millisecond. Length of fading.
The default setting value is 1000.

* Length of fading out when a motion is finished.
You can make settings of it with the setFadeIn function, and get it with the getFadeIn function.
Specify the length of fading out millisecond.
The default setting value is 1000.

* ON/OFF to play loop
You can make settings of it with the setLoop function, and get the present value with the isLoop function.
It will be played from the beginning when it is finished if you set "true".
It will continue loop playing endlessly until it is interrupted by other motion or received a command to terminate.
The default setting value is "false" (not loop).

Setting examples (*make settings of them before playing a motion)
motion->setFadeIn( 1000 );//Set the length of fading in as 1000ms
motion->setFadeOut( 1000 );//Set the length of fading out as
1000ms
motion->setLoop( true );//Do loop play


2-a. Create instances of the motion management class

Live2DMotion class is used to load and set individual motion files, and the MotionQueueManager class is used to apply above motion files to the model.

MotionQueueManager* motionManager = new MotionQueueManager();//Create motion management class



2-b. Play a motion

The startMotion function of MotionQueueManager is used to play a motion of Play simultaneously of the motion.
The second parameter is to specify to delete it from the memory or not when a motion is finished.
If you select "true", "delete" is invoked automatically inside the Live2D to delete it from the memory.
You can use C++ language only.


motionManager->startMotion( motion, false );//Play the motion



2-c. Update the Motion Parameter of the model

Without relating to the model, the animation is not executed even if you play a motion.
The updateParam function is used to set the present Motion Parameter playing to the model.
You can adjust the play speed as well.
Details.

motionManger->updateParam( live2DModel );//Update the motion




2-d. Stop the motion

The motion will be finished automatically when playing is finished, however you can use the stopAllMotions function to stop it when you want to.
Two or more motions are played simultaneously during fading, and all of them will be stopped to be finished if you used this function.

motionManger->stopAllMotions();//Stop the motion