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

MovingEntity类中的静态方法,用于从JSON对象中创建一个MovingEntity实例。该方法接受一个JSON对象作为入参,并返回一个MovingEntity实例。

语法

MovingEntity.fromJSON(jsonObj);

参数

  • jsonObj: 必选,一个JSON对象,包括下列必选字段:
字段名 类型 说明
id Number 实体的唯一标识符
position Object 实体的当前位置,包括 xy 两个字段
velocity Object 实体的当前速度向量,包括 xy 两个字段
maxSpeed Number 实体的最大速度
mass Number 实体的质量
radius Number 实体的半径
scale Object 实体的当前比例,包括 xy 两个字段

返回值

  • 若入参合法,则返回一个新的MovingEntity实例,否则返回 null

示例

const jsonObj = {
  id: 1,
  position: { x: 0, y: 0 },
  velocity: { x: 0, y: 0 },
  maxSpeed: 10,
  mass: 1,
  radius: 20,
  scale: { x: 1, y: 1 }
};

const entity = MovingEntity.fromJSON(jsonObj);