basically, whenever I'm trying to use drawImage(), it won't display the image on the screen. I've tried looking around for some solutions but nothing is working for me.
things i've tried
function createStar(){
let drawstarImage = ()=> {
ctx.drawImage(starImage, 0, 0)
}
starImage.onload = drawstarImage;
starImage.onload = ctx.drawImage(starImage, 0, 0)
Here's the code I have now
js:
/** @type {HTMLCanvasElement} */
const canvas = document.getElementById("canvas1");
const ctx = canvas.getContext("2d");
const starImage = new Image();
starImage.src = '../Assets Folder/starImage.png';
ctx.drawImage(starImage, 0, 0);
css:
body {
width: 100%;
height: 100%;
user-select: none;
}
canvas {
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background-color:rgb(33, 96, 33);
}
html:
<canvas id="canvas1"></canvas>
If possible can you explain why it's happening because I'm new to web development. Also thank you for helping.