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

update

update 是 Yuka 时间管理模块中的一个方法,用于更新时间管理器的内部计时器。该方法在每个帧中被调用,并且负责计算时间间隔以及更新每个受时间间隔影响的对象。

语法

time.update( delta, timestamp );

参数

  • delta (number): 上一次更新时间和当前时间之间的时间间隔(以毫秒为单位)。
  • timestamp (number): 当前时间的时间戳(以毫秒为单位)。

返回值

无返回值

示例

let time = new YUKA.Time();
let lastTime = Date.now();

function animate() {

    const now = Date.now();
    const delta = now - lastTime;

    // 调用update方法
    time.update(delta, now);
    
    lastTime = now;
}

在上面的示例中,animate() 函数是一个用于每个帧进行调用的动画循环函数。在每个循环中,我们首先计算上一次 animate() 函数调用和当前时间之间的时间间隔 delta,然后将它传递给 time.update() 方法。在 time.update() 方法的内部,Yuka 更新每个受时间间隔影响的对象。

其他信息

  • update 方法负责更新内部计时器,该计时器通过 time.getDeltaTime() 可以访问。
  • update 方法还负责更新时间管理模块中所有注册的时间插件/系统,以及其它模块中受时间间隔影响的对象。