Represents a single timer instance.
Attributes:
name (str): Unique identifier for the timer
start_time (float): When the timer was started (in seconds since epoch)
duration (float): How long the timer runs (in seconds)
callback (Optional[Callable]): Function to call when timer completes
callback_args (tuple): Arguments to pass to the callback function
callback_kwargs (dict): Keyword arguments to pass to the callback function
repeats (bool): Whether the timer should restart after completion
paused (bool): Whether the timer is currently paused
paused_time (float): How long the timer has been paused
destroyed (bool): Whether the timer has been marked for removal
name: str = None
start_time: float = None
duration: float = None
callback: Optional[Callable] = None
callback_args: tuple = field(default_factory=tuple)
callback_kwargs: dict = field(default_factory=dict)
repeats: bool = False
paused: bool = False
paused_time: float = 0.0
destroyed: bool = False
No methods defined.
Main timer manager for LunaEngine.
Manages multiple timers, updates them, and triggers callbacks.
Should be updated every frame in the game loop via update() method.
Example:
>>> timer = Timer()
>>> timer.add("enemy_spawn", 2.0, spawn_enemy, repeats=True)
>>> # In game loop:
>>> while running:
>>> timer.update()
def __init__(self: Any) -> None
def add(self: Any, name: str, duration: float, callback: Optional[Callable] = None, callback_args: tuple = (), callback_kwargs: dict = None, repeats: bool = False) -> bool
def add_timer_to(self: Any, duration: float, callback: Callable, callback_args: tuple = (), callback_kwargs: dict = None, repeats: bool = False) -> str
def remove(self: Any, name: str) -> bool
def destroy(self: Any, name: str) -> bool
def pause(self: Any, name: str) -> bool
def resume(self: Any, name: str) -> bool
def reset(self: Any, name: str) -> bool
def get_elapsed(self: Any, name: str) -> Optional[float]
def get_remaining(self: Any, name: str) -> Optional[float]
def is_done(self: Any, name: str) -> Optional[bool]
def exists(self: Any, name: str) -> bool
def is_paused(self: Any, name: str) -> Optional[bool]
def clear(self: Any) -> None
def update(self: Any) -> List[str]
def wait_for_end(self: Any, name: str, timeout: float = 0.0) -> bool
def get_all_timers(self: Any) -> List[str]
def get_timer_count(self: Any) -> int
def get_global_timer() -> Timer
Get or create the global singleton timer instance.
Returns:
Timer: Global timer instance
Example:
>>> from lunaengine.utils.timer import get_global_timer
>>> timer = get_global_timer()
>>> timer.add("global_timer", 1.0, lambda: print("Global timer fired!"))