CCCooldownTimer
CCCooldownTimer
Cocos2DA 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
The total duration of the timer in seconds.
The elapsed time since the timer was last reset.
Propertys
Whether the timer has completed (elapsed >= duration).
Progress from 0.0 (just started) to 1.0 (complete).
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.BooleanExample
Update(float)
Update(float)(System.Single dt)Advances the timer by dt seconds.
Parameters:
dt (System.Single)Example