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

neighbors

neighborsGameEntity类的一个方法,用于获取一个实体周围的所有相邻实体。

语法

entity.neighbors(radius, [types]);

参数

  • radius :(必需) 以该实体为中心周围的半径。可以是一个数字或一个包含[x, y]坐标的数组。如果是数字,则其单位是像素。如果是一个数组,则数组的第一个元素是横向距离,第二个元素是纵向距离。
  • types :(可选) 如果提供,则它应该是一个字符串数组,其中包含我们希望返回的实体类型。如果未提供,则它将返回所有类型的实体。

返回值

返回与该实体相邻的所有实体集合。该集合是一个包含实体对象的数组。

示例

var player = new GameEntity();
var enemies = new GameEntity();
var friend = new GameEntity();

var allEntities = [player, enemies, friend];

player.neighbors(50, ['enemies','friend']); 
// 返回一个数组,其中包含半径50内所有类型为'enemies'和'friend'的实体对象