I making a game in HTML5 and this image wont draw. In the chrome js console it says there's nothing wrong with it.
Declaring the image: var wall1 = new Image();
calling the onload:
function render(arg1, arg2, arg3){
wall1.onload = drawwall(arg1, arg2, arg3);
wall1.src = "assets/slide.jpg";
}
Draw wall function:
function drawwall(numb, dist, hm){
ctx.drawImage(wall1,numb*4,4,4,height[hm]*3/dist,numb*4,1,4,height[hm]*3/dist);
}
I've tried return ctx.drawImage(...
and return Function(){ctx.drawImage(...
but it still wont work.
Change this:
wall1.onload = drawwall(arg1, arg2, arg3);
To this
wall1.onload = function() { drawwall(arg1, arg2, arg3); };
This is necessary because you need to assign a function to the onload
property. In the erroneous code you were assigning the result of invoking a function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.