0
Я все еще учась делать вещи на холсте, как этот. Отображение объекта прямоугольника в координатах y.Uncaught TypeError: Не удается прочитать свойство 'render' of undefined
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(); });
Ах да я вижу! Спасибо чувак! – user3323654
Я попробовал сделать изображение oop. Но это невозможно сделать, хотя я использовал тот же формат кода. Функция landObj() { \t \t var land = new Изображение(); \t \t land.src = "land.png"; \t \t this.x = 0, this.y = 0, this.w = 0, this.h = 0; \t \t this.render = функция (CTX, лк, LY, ЛМ, LH) { \t \t \t ctx.drawImage (земля, х, у, ш, ч); \t \t}} \t \t \t \t вар Земля1 = новый landObj(); \t \t function animate() { \t ctx.clearRect (0,0, cW, cH); \t \t land1.render (ctx, 0, a.y, 50, 50); \t \t land1.y ++; \t} – user3323654