jjwallace Posted March 3, 2016 Share Posted March 3, 2016 ////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 More sharing options...
rich Posted March 3, 2016 Share Posted March 3, 2016 `var textTimer` is almost certainly creating a locally scoped variable (local to the create function). So the update function cannot see it, as it's out of scope. Link to comment Share on other sites More sharing options...
jjwallace Posted March 3, 2016 Author Share Posted March 3, 2016 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 More sharing options...
rich Posted March 3, 2016 Share Posted March 3, 2016 Need to see how your State is structured to know what to suggest. Typically you'd put 'this.textTimer' in the constructor, so it's a class level property. Then you can reference it from any function. Link to comment Share on other sites More sharing options...
erest0r Posted July 11, 2016 Share Posted July 11, 2016 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 More sharing options...
Recommended Posts