Animation / Animation
Animation Class
animation
Animation refers to simulating the movement and behavior of objects or character through a series of continuous image or model changes. When you are playing a role-playing game, the character you control needs to walk, jump, attack, etc. These actions are all achieved through animation.
How to use Animation?
To play an animation resource, you need to execute the loadAnimation method in Character, download and load an animation resource.
loop 、length、speed Property modify animation stance objects; Call the play method to play this animation resource.
To stop an animated object, you can directly call stop on the animated object.
In the playback step, you can add a callback function to the animation object using the onFinished delegate before call the play function. Because animation is played only on the client side, the playback completion callback will only be triggered on the client side The playback completion callback will only be triggered after the natural playback of the animation is completed. Calling stop() during the animation playback or playing other animations that interrupt the currently playing animation will not trigger the playback completion callback.
Should I load animation on the client or server?
When calling play, it will automatically determine whether to perform network synchronization based on the current character's network status and the end it is on.
If the character is on the server side, perform animation playback on all clients (animation is first create on the server and copy to the client); If the character is on the client side, the animation will be played locally.
Precautions
Please do not use new create directly. LoadAnimation can return to animation for more detailed animation control.
Table of contents
Accessors
assetId(): string other |
---|
Obtain the animation resource ID. At present, animation asset are uploaded by art creators in the left column of the editor. mouse points to the GUID of animation. |
blendInMode(): AnimationBlendMode |
Get animation mixing time |
blendInTime(): number |
Get animation mixing time |
blendOutMode(): AnimationBlendMode |
Get animation mixing time |
blendOutTime(): number |
Get animation mixing time |
isPlaying(): boolean other |
Whether to play or not |
length(): number |
Obtain the animation duration. The duration of the associated animation in the current animation object is in seconds. |
loop(): number other |
Get the number of animation playback loops. |
onFinish(): MulticastDelegate <() => void > other |
Play end delegate. |
slot(): AnimSlot |
Get animation Play slot |
speed(): number other |
Get the playback rate of animation |
startTime(): number other |
Get animation start time |
Methods
pause(): boolean other |
---|
Pause animation |
play(): boolean other |
Play the animation. Play the animation from the start of the animation asset. The effective range is bound to the character create mode. |
resume(): boolean other |
Redo animation |
stop(): boolean other |
Stop playing animation |
Accessors
assetId
• | ||
---|---|---|
Obtain the animation resource ID. At present, animation asset are uploaded by art creators in the left column of the editor. mouse points to the GUID of animation. After that, it will open the channel for developers to upload their animation asset. After uploading them to the MW editor, you can use the animation asset you uploaded. Returns
|
blendInMode
• | • | ||||
---|---|---|---|---|---|
Get animation mixing time Returns
| Set animation mixing time AlphaBlend Option Parameters
|
blendInTime
• | • | ||||
---|---|---|---|---|---|
Get animation mixing time Returns
| Set animation mixing time Parameters
|
blendOutMode
• | • | ||||
---|---|---|---|---|---|
Get animation mixing time Returns
| Set animation mixing time Parameters
|
blendOutTime
• | • | ||||
---|---|---|---|---|---|
Get animation mixing time Returns
| Set animation mixing time Parameters
|
isPlaying
• | ||
---|---|---|
Whether to play or not The server-side call does not take effect. True indicates that the animated object is currently playing, while false indicates that the animated object is not playing. Usage example: drag the used asset: "1470020380" into the priority loading column. Create a script called 'Instance-Animation_isPlay', place it in the object bar, open the script, enter the following code to save, run the game, load the dance animation on the player character, and modify the loop count to 10, doubling the playback speed. Delegate the addition of a function to 'Animation Completed' and play an upgrade effect. Press keyboard "1" to start playing the animation. Press keyboard "2" to pause the animation playback. Press "3" on the keyboard to continue playing the animation. Press "4" on the keyboard to stop playing animation. The code is as follows: ts
Returns
|
length
• | ||
---|---|---|
Obtain the animation duration. The duration of the associated animation in the current animation object is in seconds. Usage example: drag the used asset: "1470020380" into the priority loading column. Create a script named "Example_Animation_Length", place it in the object bar, open the script, enter the following code to save, run the game, load dance animation on the Player's character, and modify the number of cycles to 10, and the playback speed to twice. Add a function to the delegate of animation Completion to play a upgrade effect. Press keyboard "1" to start playing the animation. Press keyboard "2" to pause the animation playback. Press "3" on the keyboard to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows: ts
Returns
|
loop
• | • | ||||
---|---|---|---|---|---|
Get the number of animation playback loops. When loop is set to 0, it can play infinitely in a loop. When the settings are complete, call the Play() function to see the character play animation. Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script called 'Instance-Animation_Loop', place it in the object bar, open the script, enter the following code to save, run the game, load the dance animation on the player character, and modify the loop count to 10, doubling the playback speed. Add a function to the delegate of animation Completion to play a upgrade effect. Press the keyboard "1" to start playing the animation. Press keyboard "2" to pause the animation playback. Press keyboard "3" to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows: ts
Returns
| Sets the number of playback cycles for the animation Parameters
|
onFinish
• | ||
---|---|---|
Play end delegate. Execute the binding function at the end of animation playback (when the animation is not interrupted and the playback is completed normally). Precautions Performance limit: the server does not play animation, only the client triggers it. Please use the delegate on the client. In several cases, the delegate 1 call the pause method 2 call the stop method 3. The animation is playing and call the play API. Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script named 'Instance-Animation_onFinish', place it in the object bar, open the script, enter the following code to save, run the game, load the dance animation on the player character, and modify the loop count to 10, doubling the playback speed. Delegate the addition of a function to 'Animation Completed' and play an upgrade effect. Press the keyboard "1" to start playing the animation. Press "2" on the keyboard to pause animation. Press "3" on the keyboard to continue playing the animation. Press "4" on the keyboard to stop playing animation. The code is as follows: ts
Returns
|
slot
• | • | ||||
---|---|---|---|---|---|
Get animation Play slot Returns
| Set animation Playback slot Parameters
|
speed
• | • | ||||
---|---|---|---|---|---|
Get the playback rate of animation Precautions Set the playback rate (there is a fusion time when animation switches, animation is too short, and animation may not be obvious when speed=1), the numerical value is unlimited, and the symbol of the rate represents the playback direction, and positive represents forward playback, Negative means reverse playback. Speed of 1 means original speed. The default value is 2. Setting this value does not change the starting point of playback Usage example: drag the used asset: "1470020380" into the priority loading column. Create a script named 'Instance-Animation_Speed', place it in the object bar, open the script, enter the following code to save, run the game, load the dance animation on the player character, and modify the loop count to 10, doubling the playback speed. Delegate the addition of a function to 'Animation Completed' and play an upgrade effect. Press keyboard "1" to start playing the animation. Press "2" on the keyboard to pause animation. Press "3" on the keyboard to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows: ts
Returns
| Set the playback speed of the animation Precautions Set the playback rate (there is a fusion time when animation switches, animation is too short, and animation may not be obvious when speed=1), the numerical value is unlimited, and the symbol of the rate represents the playback direction, and positive represents forward playback, Negative means reverse playback. Speed of 1 means original speed. The default value is 1. Setting this value will not change the starting point of playback Parameters
|
startTime
• | • | ||||
---|---|---|---|---|---|
Get animation start time Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script called 'Instance-Animation_Loop', place it in the object bar, open the script, enter the following code to save, run the game, load the dance animation on the player character, and modify the loop count to 10, doubling the playback speed. Add a function to the delegate of animation Completion to play a upgrade effect. Press the keyboard "1" to start playing the animation. Press keyboard "2" to pause the animation playback. Press keyboard "3" to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows: ts
Returns
| Set the start point time of the animation Precautions Final effective range [0, animation length] Parameters
|
Methods
pause
• pause(): boolean
other
Pause animation
Returns
boolean | Pause Results |
---|
Precautions
The onFinish delegate will not be triggered. The effective range is bound to the character create mode.
Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script named "Example_Animation_Pause", place it in the object bar, open the script, enter the following code to save, run the game, load dance animation on the Player's character, and modify the number of cycles to 10, and the playback speed to twice. Add a function to the delegate of animation Completion to play a upgrade effect. Press the keyboard "1" to start playing the animation. Press "2" on the keyboard to pause animation. Press keyboard "3" to continue playing the animation. Press "4" on the keyboard to stop playing animation. The code is as follows:
@Component
export default class Example_Animation_Pause extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}
@Component
export default class Example_Animation_Pause extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}
play
• play(): boolean
other
Play the animation. Play the animation from the start of the animation asset. The effective range is bound to the character create mode.
Returns
boolean | Play result |
---|
Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script named "Example_Animation_Play", place it in the object bar, open the script, enter the following code to save, run the game, load the dance animation on the Player's character, and modify the number of cycles to 10, and the playback speed to twice. Add a function to the delegate of animation Completion to play a upgrade effect. Press the keyboard "1" to start playing the animation. Press "2" on the keyboard to pause animation. Press "3" on the keyboard to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows:
@Component
export default class Example_Animation_Play extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}
@Component
export default class Example_Animation_Play extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}
resume
• resume(): boolean
other
Redo animation
Returns
boolean | Continue Results |
---|
Precautions
Continue animation playback from the current position. The effective scope is bound to the role creation method.
Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script named "Example_Animation_Resume", place it in the object bar, open the script, enter the following code to save, run the game, load dance animation on the Player's character, and modify the number of cycles to 10, and the playback speed to twice. Add a function to the delegate of animation Completion to play a upgrade effect. Press the keyboard "1" to start playing the animation. Press keyboard "2" to pause the animation playback. Press "3" on the keyboard to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows:
@Component
export default class Example_Animation_Resume extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}
@Component
export default class Example_Animation_Resume extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}
stop
• stop(): boolean
other
Stop playing animation
Returns
boolean | Stop result |
---|
Precautions
Do not trigger the animation end callback. The effective scope is bound to the role creation method.
Usage example: Drag the resource "1470020380" into the priority loading bar. Create a script named "Example_Animation_Stop", place it in the object bar, open the script, enter the following code to save, run the game, load dance animation on the Player's character, and modify the number of cycles to 10, and the playback speed to twice. Add a function to the delegate of animation Completion to play a upgrade effect. Press the keyboard "1" to start playing the animation. Press "2" on the keyboard to pause animation. Press "3" on the keyboard to continue playing the animation. Press keyboard "4" to stop playing the animation. The code is as follows:
@Component
export default class Example_Animation_Stop extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}
@Component
export default class Example_Animation_Stop extends Script {
// When the script is instantiated, this function will be called before the first frame update
protected onStart(): void {
// The following code is only executed on the client side
if(SystemUtil.isClient()) {
// Get the current client Player
let myPlayer = Player.localPlayer;
// Get Player control character
let myCharacter = myPlayer.character;
// Load a dance animation for the character
let danceAnimation = myCharacter.loadAnimation("14700");
// Property of animation
Console.log ("animation duration"+danceAnimation. length);
// Loop playback 10 times
danceAnimation.loop = 10;
// 2x playback speed
danceAnimation.speed = 2;
// Delegate the addition of a function to 'Animation Completed' and play an upgraded special effect
danceAnimation.onFinish.add(() => {
EffectService.playOnGameObject("20380", myCharacter, {slotType: HumanoidSlotType.Root});
});
// Add a key method: press the keyboard "1" to start playing
InputUtil.onKeyDown(Keys.One, () => {
danceAnimation.play();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "2" on the keyboard to pause playback
InputUtil.onKeyDown(Keys.Two, () => {
danceAnimation.pause();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "3" on the keyboard to continue playing
InputUtil.onKeyDown(Keys.Three, () => {
danceAnimation.resume();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
// Add a key method: press "4" on the keyboard to stop playing
InputUtil.onKeyDown(Keys.Four, () => {
danceAnimation.stop();
Console.log ("animation playing"+danceAnimation. isPlaying);
});
}
}
}