the error:
Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLCanvasElement or HTMLImageElement or HTMLVideoElement or ImageBitmap or OffscreenCanvas or SVGImageElement or VideoFrame)'.
here is the player value in the editor:
let player = {
x: 100,
y: 100,
h: 0,
vh: 0,
v: 0,
hp: 100,
controls: {
turnLeft: false,
turnRight: false,
accelerate: false,
deccelerate: false,
},
sprite: document.getElementById("fighter3"),
}
here is the player value in the console:
controls:
{turnLeft: false, turnRight: false, accelerate: false, deccelerate: false}
h: 0
hp: 100
sprite: null
v: 0
vh: 0
x: 100
y: 100
and here is the draw command:
ctx.drawImage(player.sprite, player.x, player.y);
I am trying to draw a sprite to canvas and when I use context.drawImage I get an error, I narrowed it down to the fact that document.getElementById("fighter3") returns null for some reason (the html id is correct).
Via Active questions tagged javascript - Stack Overflow https://ift.tt/5z1NAW2
Comments
Post a Comment