AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

fromJSON

简介

fromJSONSmoother 中的一个方法,用于将一个 JSON 数据解析为平滑器。

语法

Smoother.fromJSON(json, options)

参数

  • json:要解析的 JSON 数据。必需的。
  • options:可选的配置对象,包括以下属性:
    • updateOnStart:平滑器启动时是否触发一次更新函数。默认为 false
    • delayStart:平滑器启动时是否延迟触发更新函数。默认为 false
    • isReverse:是否按相反的顺序解析 JSON 数据。默认为 false

返回值

返回一个 Smoother 对象。

示例

const data = '{"property": "scrollTop", "start": 0, "target": 100, "duration": 1000}';
const options = { updateOnStart: true };
const smoother = Smoother.fromJSON(data, options);

smoother.onUpdate = function(value) {
  // Todo: 处理 value 值
};

smoother.start();

注意事项

  • json 参数必须是一个有效的 JSON 字符串。
  • 解析失败会抛出 SyntaxError
  • options 中的属性值须是布尔型或数值型。