There is a ball class.
function Ball(x, y, id) { this.x = x; this.y = y; this.id = id; Ball.prototype.draw = function() { ctx.drawImage(sprite1, 0, 0); } }
How can I use "this.x" and "this.y" instead of zeros in the drawImage () function?
There is a ball class.
function Ball(x, y, id) { this.x = x; this.y = y; this.id = id; Ball.prototype.draw = function() { ctx.drawImage(sprite1, 0, 0); } }
How can I use "this.x" and "this.y" instead of zeros in the drawImage () function?
For example:
Ball = function ( x, y, id){ this.x = x; this.y = y; this.id = id; } Ball.prototype.draw = function (){ ctx.drawImage( sprite1, this.x, this.y ); }
Pay attention to ctx и sprite1
, IMHO - if they are some global objects, then:
Source: https://ru.stackoverflow.com/questions/72747/
All Articles