WaitForSeconds

Namespace:

namespace Lenga\Engine\Core;

class WaitForSeconds

Methods

getDuration

public function getDuration()

keepWaiting

public function keepWaiting()

Example

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\WaitForSeconds;

class DelayedAction extends Behaviour
{
    public function start(): void
    {
        $this->startCoroutine($this->delayedExplosion());
    }

    private function delayedExplosion(): \Generator
    {
        Debug::log('Explosion will happen in 3 seconds...');

        // Wait 3 real-time seconds
        yield new WaitForSeconds(3.0);

        Debug::log('Explosion!');
        $this->explode();
    }

    private function explode(): void
    {
        // Explosion logic here
    }
}