I have an object for my canvas which is stored as an object, i stored the canvas to the object like so:
window.canvas = new Object();
temp = document.getElementById('canvas_id');
canvas[objname] = new Object();
canvas[objname].ctx = temp.getContext("2d");
The problem I am having how ever is i cannot use ctx for draw image….
I do this in my draw function:
Just so you know the image is set like:
img = new Image();
img.src = 'images/0.png';
Later in the script the draw:
canvas['canvas1'].ctx.drawImage(img.src,abposx,abposy);
Problem is i get a type error which says this:
Uncaught TypeError: Type error
Any ideas if it is because I have placed ctx in the object and so cannot call ctx like that??
Try passing the image itself instead of
image.srctry the below:I hope that helps!
this is a code sample :
from https://developer.mozilla.org/samples/canvas-tutorial/3_1_canvas_drawimage.html