...

View Full Version : Image object problem,



kingkong22
11-18-2012, 11:35 PM
Hi, someone can help plese!!!!

I dont know what happened with the source because after the script executes, there is nothing in the canvas

function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();

img.onload = function(){
ctx.drawImage(img,0,0);
}
}

img.src = 'images/backdrop.png';

Can someone help please!!!

devnull69
11-19-2012, 11:21 AM
EDIT: You closed the function too early. The img.src line has to go into the function, so just move the last closing bracket } after the img.src line



function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();

img.onload = function(){
ctx.drawImage(img,0,0);
}
img.src = 'images/backdrop.png';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum