remove naturalSpeed property of animation function

This commit is contained in:
printempw 2018-02-12 12:23:05 +08:00
parent 5b215cdcca
commit a0730f8da8
2 changed files with 18 additions and 21 deletions

View File

@ -15,7 +15,6 @@ class AnimationHandle {
this.speed = this._speed = 1.0; this.speed = this._speed = 1.0;
this._lastChange = null; this._lastChange = null;
this._lastChangeX = null; this._lastChangeX = null;
this._animationNaturalSpeed = animation.naturalSpeed || 1.0;
} }
play(player, time) { play(player, time) {
if (this._lastChange === null) { if (this._lastChange === null) {
@ -32,7 +31,7 @@ class AnimationHandle {
} }
if (this.paused === false) { if (this.paused === false) {
let dt = time - this._lastChange; let dt = time - this._lastChange;
let x = this._lastChangeX + (this.speed * this._animationNaturalSpeed) * dt; let x = this._lastChangeX + this.speed * dt;
invokeAnimation(this.animation, player, x); invokeAnimation(this.animation, player, x);
} }
} }
@ -59,9 +58,12 @@ class CompositeAnimation {
let WalkingAnimation = (player, time) => { let WalkingAnimation = (player, time) => {
let skin = player.skin; let skin = player.skin;
// Multiply by animation's natural speed
time *= 8;
// Leg swing // Leg swing
skin.leftLeg.rotation.x = Math.sin(time) * 0.3; skin.leftLeg.rotation.x = Math.sin(time) * 0.5;
skin.rightLeg.rotation.x = Math.sin(time + Math.PI) * 0.3; skin.rightLeg.rotation.x = Math.sin(time + Math.PI) * 0.5;
// Arm swing // Arm swing
skin.leftArm.rotation.x = Math.sin(time + Math.PI) * 0.5; skin.leftArm.rotation.x = Math.sin(time + Math.PI) * 0.5;
@ -71,19 +73,19 @@ let WalkingAnimation = (player, time) => {
skin.rightArm.rotation.z = Math.cos(time + Math.PI) * 0.03 - basicArmRotationZ; skin.rightArm.rotation.z = Math.cos(time + Math.PI) * 0.03 - basicArmRotationZ;
// Head shaking with different frequency & amplitude // Head shaking with different frequency & amplitude
skin.head.rotation.y = Math.sin(time / 2) * 0.2; skin.head.rotation.y = Math.sin(time / 4) * 0.2;
skin.head.rotation.x = Math.sin(time / 3) * 0.15; skin.head.rotation.x = Math.sin(time / 5) * 0.1;
// Always add an angle for cape around the x axis // Always add an angle for cape around the x axis
let basicCapeRotationX = Math.PI * 0.06; let basicCapeRotationX = Math.PI * 0.06;
player.cape.rotation.x = Math.sin(time / 1.5) * 0.06 + basicCapeRotationX; player.cape.rotation.x = Math.sin(time / 1.5) * 0.06 + basicCapeRotationX;
}; };
WalkingAnimation.naturalSpeed = 5;
let RunningAnimation = (player, time) => { let RunningAnimation = (player, time) => {
let skin = player.skin; let skin = player.skin;
time *= 15;
// Leg swing with larger amplitude // Leg swing with larger amplitude
skin.leftLeg.rotation.x = Math.cos(time + Math.PI) * 1.3; skin.leftLeg.rotation.x = Math.cos(time + Math.PI) * 1.3;
skin.rightLeg.rotation.x = Math.cos(time) * 1.3; skin.rightLeg.rotation.x = Math.cos(time) * 1.3;
@ -112,14 +114,10 @@ let RunningAnimation = (player, time) => {
// You shouldn't glance right and left when running dude :P // You shouldn't glance right and left when running dude :P
}; };
RunningAnimation.naturalSpeed = 13;
let RotatingAnimation = (player, time) => { let RotatingAnimation = (player, time) => {
player.rotation.y = time; player.rotation.y = time;
}; };
RotatingAnimation.naturalSpeed = 1;
export { export {
CompositeAnimation, CompositeAnimation,
invokeAnimation, invokeAnimation,

View File

@ -1,10 +1,9 @@
import { PlayerObject } from "./model"; import { PlayerObject } from "./model";
export interface IAnimation { export interface IAnimation {
naturalSpeed?: number;
play(player: PlayerObject, time: number): void; play(player: PlayerObject, time: number): void;
} }
export type AnimationFn = ((player: PlayerObject, time: number) => void) & { naturalSpeed?: number }; export type AnimationFn = (player: PlayerObject, time: number) => void;
export type Animation = AnimationFn | IAnimation; export type Animation = AnimationFn | IAnimation;
export function invokeAnimation( export function invokeAnimation(