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 () {

// Let's play this game!
//setInterval(main, 2000); // Execute as fast as possible
5 Years
Discussion Span
Last Post by Airshow

hai Yarra,

could you tell me how you initialize the values for these bgReady,heroReady,monsterReady variables in your script?

based on the values of these variables you could not run the render() method directly i think (what i mean is if the values of all these variables are 'false' then the function not works)

and also you have forgotten to give the code relating to these variables

it will be easy for us if we look at that code (post that code also)

happy coding

Edited by radhakrishna.p: getting clarity on then problem


if I just invoker "render();" the function does not run

Does not run, or does not have any effect?

Two completely different animals.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.