Код IT
← Каталог

Canvas — модель, update, render и игровой цикл

Минимальная 2D-игра: отдельные слои данных, физики, отрисовки и requestAnimationFrame.

html graphicscanvasencyclopediabeginner embed URL статья в энциклопедии
HTML index.html
<!DOCTYPE html>
<html lang="ru">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Модель → update → render</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 1rem; background: #0f172a; color: #e2e8f0; }
    canvas { display: block; background: #1e293b; border-radius: 8px; margin-top: 0.5rem; }
    code { background: #334155; padding: 0.1em 0.35em; border-radius: 4px; }
  </style>
</head>
<body>
  <h1>Шар на canvas</h1>
  <p>Слои в <code>main.js</code>: <strong>модель</strong> → <strong>update</strong> → <strong>render</strong> → <strong>цикл</strong>.</p>
  <canvas id="game" width="480" height="320" aria-label="Игровое поле"></canvas>
  <script src="main.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="ru">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Модель → update → render</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 1rem; background: #0f172a; color: #e2e8f0; }
    canvas { display: block; background: #1e293b; border-radius: 8px; margin-top: 0.5rem; }
    code { background: #334155; padding: 0.1em 0.35em; border-radius: 4px; }
  </style>
</head>
<body>
  <h1>Шар на canvas</h1>
  <p>Слои в <code>main.js</code>: <strong>модель</strong> → <strong>update</strong> → <strong>render</strong> → <strong>цикл</strong>.</p>
  <canvas id="game" width="480" height="320" aria-label="Игровое поле"></canvas>
  <script src="main.js"></script>
</body>
</html>