wz->attach($this->engine); $this->time = 0.0; } public function update(float $dt): void { $this->time += $dt; $this->wz->tick($dt); } /** A canvas on the 640 x 480 screen, centred and zoomed in the window. */ /** @param array{0: float, 1: float, 2: float, 3: float}|null $box the part of the 640 x 480 screen that fills the window (null: all of it) */ protected function canvas(Renderer $r, string $background = '#000000', ?array $box = null): Canvas { $r->clear($background); $c = new Canvas($r, $this->sdl()); $c->skin = $this->wz->skin; [$bx, $by, $bw, $bh] = $box ?? [0.0, 0.0, (float)self::W, (float)self::H]; $c->scale = min($r->getWidth() / $bw, $r->getHeight() / $bh); $c->at(($r->getWidth() / $c->scale - $bw) / 2 - $bx, ($r->getHeight() / $c->scale - $bh) / 2 - $by); return $c; } protected function anyInput(): bool { $input = $this->engine->input; return $input->getKeyboard()->anyPressed() || $input->getMouse()->isPressed(1) || $input->getMouse()->isPressed(3) || $input->getGamepad()->anyPressed(); } protected function showCursor(bool $on): void { // no display (tests, the playground's sandbox): no pointer to hide if (function_exists('SDL_ShowCursor') && !\JumPHP\Kernel\Platform::isHeadless()) { @\SDL_ShowCursor($on ? 1 : 0); } } }