Jump to content

Uncaught TypeError: Cannot set property 'text' of undefined


jjwallace
 Share

Recommended Posts

////This makes no sense! Any Help?

var textTimer = this.add.text(this.world.centerX, this.world.centerY + 40, "0", { font: "48px Arial", fill: "#ff0044", align: "center" });

//update

var gameTimer = Math.floor(totalTime / 30);
this.textTimer.text = gameTimer; <---------- ERROR ON THIS LINE

///// ERROR: Uncaught TypeError: Cannot set property 'text' of undefined

Link to comment
Share on other sites

Yah i figured this was the case.  I am not really sure how to carry the scope without dispatch causing a undefined in phaser.

//here is me code.....

paintGame: function (){  
        var textScore = this.add.text(this.world.centerX, this.world.centerY, "0", { font: "48px Arial", fill: "#ff0044", align: "center" });
        var textTimer = this.add.text(this.world.centerX, this.world.centerY + 40, "0", { font: "48px Arial", fill: "#ff0044", align: "center" });
    },
    
    update: function () {        
            var gameTimer = Math.floor(totalTime / 30);
            this.textTimer.text = gameTimer;

//this.textTimer.text = this.gameTimer;
    },

Link to comment
Share on other sites

  • 4 months later...

Sorry for reopening this thread, but i have the same problem, i'm having a scoreText to show the player score, in my create method it is like this: 
 

this.scoreText = this.game.add.text(5, 5, 'Points: ' + score, { font: '18px Arial', fill: '#0095DD' });

my score variable is global, then i have a ballHitBrick method like this:

Game.prototype.ballHitBrick = function (ball, brick) {
    brick.kill();
    score += 10;
    this.scoreText.text = 'Points: ' + score;
};

when the ball hit a brick i get the same message as the thread's title "Cannot set property text of undefined"

 

EDIT: I want to apologize, i found my mistake,i forgot some parameters in physics.arcade.collide method.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...