From a0730f8da8d1d3d3b7a6d55e81073847f30a304a Mon Sep 17 00:00:00 2001 From: printempw Date: Mon, 12 Feb 2018 12:23:05 +0800 Subject: [PATCH] remove naturalSpeed property of animation function --- src/animation.js | 36 +++++++++++++++++------------------- types/animation.d.ts | 3 +-- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/animation.js b/src/animation.js index d12f0d2..bbacf6a 100644 --- a/src/animation.js +++ b/src/animation.js @@ -15,7 +15,6 @@ class AnimationHandle { this.speed = this._speed = 1.0; this._lastChange = null; this._lastChangeX = null; - this._animationNaturalSpeed = animation.naturalSpeed || 1.0; } play(player, time) { if (this._lastChange === null) { @@ -32,7 +31,7 @@ class AnimationHandle { } if (this.paused === false) { 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); } } @@ -59,40 +58,43 @@ class CompositeAnimation { let WalkingAnimation = (player, time) => { let skin = player.skin; + // Multiply by animation's natural speed + time *= 8; + // Leg swing - skin.leftLeg.rotation.x = Math.sin(time) * 0.3; - skin.rightLeg.rotation.x = Math.sin(time + Math.PI) * 0.3; + skin.leftLeg.rotation.x = Math.sin(time) * 0.5; + skin.rightLeg.rotation.x = Math.sin(time + Math.PI) * 0.5; // Arm swing - skin.leftArm.rotation.x = Math.sin(time + Math.PI) * 0.5; + skin.leftArm.rotation.x = Math.sin(time + Math.PI) * 0.5; skin.rightArm.rotation.x = Math.sin(time) * 0.5; - let basicArmRotationZ = Math.PI * 0.02; - skin.leftArm.rotation.z = Math.cos(time) * 0.03 + basicArmRotationZ; + let basicArmRotationZ = Math.PI * 0.02; + skin.leftArm.rotation.z = Math.cos(time) * 0.03 + basicArmRotationZ; skin.rightArm.rotation.z = Math.cos(time + Math.PI) * 0.03 - basicArmRotationZ; // Head shaking with different frequency & amplitude - skin.head.rotation.y = Math.sin(time / 2) * 0.2; - skin.head.rotation.x = Math.sin(time / 3) * 0.15; + skin.head.rotation.y = Math.sin(time / 4) * 0.2; + skin.head.rotation.x = Math.sin(time / 5) * 0.1; // Always add an angle for cape around the x axis let basicCapeRotationX = Math.PI * 0.06; player.cape.rotation.x = Math.sin(time / 1.5) * 0.06 + basicCapeRotationX; }; -WalkingAnimation.naturalSpeed = 5; - let RunningAnimation = (player, time) => { let skin = player.skin; + time *= 15; + // 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; // Arm swing - skin.leftArm.rotation.x = Math.cos(time) * 1.5; + skin.leftArm.rotation.x = Math.cos(time) * 1.5; skin.rightArm.rotation.x = Math.cos(time + Math.PI) * 1.5; - let basicArmRotationZ = Math.PI * 0.1; - skin.leftArm.rotation.z = Math.cos(time) * 0.1 + basicArmRotationZ; + let basicArmRotationZ = Math.PI * 0.1; + skin.leftArm.rotation.z = Math.cos(time) * 0.1 + basicArmRotationZ; skin.rightArm.rotation.z = Math.cos(time + Math.PI) * 0.1 - basicArmRotationZ; // Jumping @@ -112,14 +114,10 @@ let RunningAnimation = (player, time) => { // You shouldn't glance right and left when running dude :P }; -RunningAnimation.naturalSpeed = 13; - let RotatingAnimation = (player, time) => { player.rotation.y = time; }; -RotatingAnimation.naturalSpeed = 1; - export { CompositeAnimation, invokeAnimation, diff --git a/types/animation.d.ts b/types/animation.d.ts index 31f2f3e..9b89563 100644 --- a/types/animation.d.ts +++ b/types/animation.d.ts @@ -1,10 +1,9 @@ import { PlayerObject } from "./model"; export interface IAnimation { - naturalSpeed?: number; 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 function invokeAnimation(