So what is going on is. For some reason if I just invoker "render();" the function does not run. But when I put it under the main(); function, and then invoke the main function under a "setInterval()" method then everythig works. Why is this?
// Draw everything
var render = function () {
//if (bgReady) {
ctx.drawImage(bgImage, 0, 0);
//}
if (heroReady) {
ctx.drawImage(heroImage, hero.x, hero.y);
}
if (monsterReady) {
ctx.drawImage(monsterImage, monster.x, monster.y);
}
};
var problem = function () {
ctx.fillStyle = "rgb(0, 0, 0)";
ctx.font = "24px Wood";
ctx.textAlign = "left";
ctx.textBaseline = "top";
var which = Math.floor(Math.random() * 6) + 0
if(which == 0){
var geofunct = "TAN";
}else if(which == 1){
var geofunct = "COS";
}else if(which == 2){
var geofunct = "SIN";
}else if(which == 3){
var geofunct = "arcTAN";
}else if(which == 4){
var geofunct = "arcCOS";
}else if(which == 5){
var geofunct = "arcSIN";
}
ctx.fillText(geofunct + ": "+which, 32, 32);
};
// The main game loop
var main = function () {
render();
problem();
};
//main();
// Let's play this game!
reset();
//setInterval(main, 2000); // Execute as fast as possible