1
0
Fork 0

fix: clear rect on every frame

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 2 years ago
parent 1763fda79a
commit 62fedcba92
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854

Binary file not shown.

@ -7,7 +7,9 @@ import { Vec2 } from './vector.js'
// Global on purpose
/** @type {Shape} */
let astronaut
/** @type {CanvasRenderingContext2D | null} */
/** @type {HTMLCanvasElement} */
let canvas
/** @type {CanvasRenderingContext2D} */
let context
/**
@ -22,13 +24,15 @@ export function app () {
return
}
context = /** @type {HTMLCanvasElement} */(game).getContext('2d')
canvas = /** @type {HTMLCanvasElement} */(game)
const ctx = canvas.getContext('2d')
if (!context) {
if (!ctx) {
console.error('Could not start game!')
return
}
context = ctx
astronaut = makeAstronaut()
tick()
}
@ -63,11 +67,7 @@ function makeAstronaut () {
/* TODO: Add some paint-FPS to UI */
// See https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#notes
function tick () {
// Impossible state
if (!context) {
return
}
context.clearRect(0, 0, canvas.width, canvas.height)
drawShape(context, astronaut)
window.requestAnimationFrame(tick)
}

@ -16,6 +16,7 @@ export function drawShape (context, shape) {
prepareCanvas(context, shape)
draw(context, shape)
context.restore()
updatePosition(shape)
updateRotation(shape)
}

Loading…
Cancel
Save