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

Recommended Answers

All 2 Replies

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

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

Does not run, or does not have any effect?

Two completely different animals.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.