[英]Uncaught TypeError: Cannot read property 'render' of undefined
i'm still learning how to do stuffs in a canvas like this one. 我仍在学习如何在这样的画布上做东西。 Rendering a rectangle object in ay coordinates. 在y坐标中渲染矩形对象。
function initCanvas(){
var ctx = document.getElementById('canvas').getContext('2d');
var cW = ctx.canvas.width, cH = ctx.canvas.height;
var y = 0, x = 0;
function rectObj(){
this.x = 0, this.y = 0;
this.render = function(ctx, lx, ly, lw, lh, clr){
ctx.fillStyle = clr;
ctx.fillRect(lx, ly, lw, lh);
}
}
var a = rectObj();
function animate(){
ctx.clearRect(0,0, cW, cH);
a.render(ctx, 0, a.y, 50, 50, "blue");
a.y++;
}
var animateInterval = setInterval(animate, 30);
}window.addEventListener('load', function(event){ initCanvas(); });
您应该使用new
运算符调用该函数:
var a = new rectObj();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.