Witam. Dlaczego tworzac obiekt w funkcji ktora odswieza sie 60 razy na sekunde funkcja draw dziala, a po za funkcja game nie dziala? Oto wycinek kodu:
var rain_1 = new Rain_1();
function game(){
rain_1.draw()
};
function Rain(){
this.x = rand(50,cw-50);
this.y = 0;
this.w = rand(10,40);
this.h =rand(30,100);
this.speed = rand(1,5);
this.gravity = function(){
this.y+=this.speed;
};
};
Rain.prototype.draw = function(){
ctx.fillStyle = 'green';
ctx.fillRect(this.x,this.y,this.w,this.h);
this.gravity();
}
function Rain_1(){
Rain.call(this);
};
Rain_1.prototype = new Rain();
Rain_1.prototype.constructor = Rain_1;
setInterval(game,1000/60);
Natomiast gdy tworze New rain_1 w srodku funkcji game, to dziala lecz nie tak jakbym chcial.