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

resolveReferences

方法描述

resolveReferences()GameEntity 对象的一个方法,用于在游戏实体中解析参考对象。

方法语法

resolveReferences(objects: { [id: string]: GameEntity }): void
  • objects: 一个包含所有需要解析参考的游戏实体的对象,对象的键名为游戏实体的ID。

方法参数

名称 必填 类型 描述
objects { [id: string]: GameEntity } 一个包含所有需要解析参考的游戏实体的对象,对象的键名为游戏实体的ID。

方法示例

const objects = {
  'healthPotion': new GameEntity('healthPotion', { ... }),
  'player': new GameEntity('player', { ... })
};

const enemy = new GameEntity('enemy', {
  ...

  components: [
    new SpriteComponent('enemy.png'),
    new HealthComponent(50),
    new DamageComponent(10, objects['player']),
    new LootComponent([
      { item: objects['healthPotion'], chance: 0.5 }
    ])
  ]
});

enemy.resolveReferences(objects);

方法说明

在游戏实体的 components 属性中,可以包含许多不同的组件,这些组件可能包含对其他游戏实体的引用,例如,一个伤害组件需要引用玩家实体才能计算伤害。在创建游戏实体时,这些引用是无法解析的。可以将所有的游戏实体存储在一个对象中,通过传入这个对象到 resolveReferences() 方法中,让游戏实体可以解析对其他游戏实体的引用,从而使组件生效。