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

Touching

描述

touching 方法用于判断当前指定的元素是否与触发区域重叠,如果重叠则返回 true,否则返回 false

用法

Yuka.TriggerRegion.touching(element, triggerRegion);

参数

  • element:要判断的元素。
  • triggerRegion:触发区域对象,包含以下属性:
    • left:触发区域左侧的 x 坐标。
    • top:触发区域顶部的 y 坐标。
    • right:触发区域右侧的 x 坐标。
    • bottom:触发区域底部的 y 坐标。

返回值

  • true:如果元素与触发区域重叠。
  • false:如果元素未与触发区域重叠。

示例

<div id="element" style="width: 50px; height: 50px; background-color: red;"></div>
<script>
    var element = document.getElementById('element');
    var triggerRegion = {
        left: 10,
        top: 10,
        right: 60,
        bottom: 60
    };
    var isTouching = Yuka.TriggerRegion.touching(element, triggerRegion);
    console.log(isTouching); // true
</script>

注意事项

  • 该方法只能在支持 getBoundingClientRect() 的浏览器中使用。