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

calculate

描述

AlignmentBehaviorcalculate 方法被用于计算在给定的 layoutcurrentPosition 的情况下,弹出框应该如何对齐目标元素。

参数

  • layout:(Object) 弹出框的 width, height, xy 坐标。
  • currentPosition:(Object) 目标元素的 xy 坐标以及其 widthheight

返回值

  • (Object) 包含 xy 坐标的对象,表示弹出框的位置。

示例

const alignmentBehavior = new Yuka.AlignmentBehavior();
const layout = { width: 200, height: 100, x: 0, y: 0 };
const currentPosition = { x: 50, y: 50, width: 20, height: 10 };
const popupPosition = alignmentBehavior.calculate(layout, currentPosition);
console.log(popupPosition); // 输出弹出框的位置 { x: 70, y: 60 }

注意事项

  • AlignmentBehaviorcalculate 方法并不会直接操作 DOM 元素的样式,需要在调用该方法之后手动设置弹出框的位置。