move image from class

n8_115

New Member
How do i access the image from a class in html5 canvas? I load an image from a class but to access and move it across the canvas I cant get access to it. I can do this without a class.The code works fine without a class.\[code\] <script> var canvas = document.getElementById('myCanvas'); var ctx = canvas.getContext('2d'); var img1_x=10; var img1_y=10; ctx.font="14px Arial"; //class loadimages function doGameLoop() { ctx.clearRect(0,0,600,400); img.m_move(); if (img1_x>30) { clearInterval(gameLoop); } } //this is how you do classes function ClassLoadImages(name1) { var img1 = new Image(); this.x=10; this.y=10; this.name1=name1; img1.src = http://stackoverflow.com/questions/15897386/name1; img1.onload = function() { ctx.drawImage(img1, img1_x, img1_y); }; };//func ClassMoveImages.prototype.m_move = function(){ this.x++; this.y++; ctx.drawImage(img1, this.x, this.y); // ctx.fillText("finished loading " ,10,40); }; var img= new ClassLoadImages('images/image4.jpg'); gameLoop = setInterval(doGameLoop, 100);</script>\[/code\]
 
Top