Skip to main content

CCCooldownTimer

CCCooldownTimer

Cocos2D

A simple cooldown/duration timer struct. Useful for tracking cooldowns, invincibility frames, combo windows, and other time-based game state. Usage: var dashCooldown = new CCCooldownTimer(0.8f); // In update loop: dashCooldown.Update(dt); if (dashCooldown.IsReady) Dash(); dashCooldown.Reset();

Type: Struct

Constructors

CCCooldownTimer(float)

Creates a new timer with the given duration. Starts ready (elapsed = duration). Call Reset() to start the cooldown.

CCCooldownTimer(float, bool)

Creates a new timer with the given duration and initial readiness.

Fields

Duration(System.Single)

The total duration of the timer in seconds.

Elapsed(System.Single)

The elapsed time since the timer was last reset.

Propertys

IsReady(System.Boolean)

Whether the timer has completed (elapsed >= duration).

Progress(System.Single)

Progress from 0.0 (just started) to 1.0 (complete).

Remaining(System.Single)

Remaining time in seconds.

Methods

Reset()

Reset()()

Resets the timer, starting the cooldown from zero.

Example

Reset(float)

Reset(float)(System.Single newDuration)

Resets the timer with a new duration.

Parameters:
newDuration (System.Single)
Example

TryConsume()

System.Boolean TryConsume()()

If the timer is ready, resets it and returns true. Otherwise returns false. Convenient one-liner: if (timer.TryFire(dt)) DoAction();

Returns:
System.Boolean
Example

Update(float)

Update(float)(System.Single dt)

Advances the timer by dt seconds.

Parameters:
dt (System.Single)
Example