Reputation: 51
Im making a program in Phaser in JavaScript and im using the statement questions.setVisible(false)
in my program, but this appears - Uncaught TypeError: question.setVisible is not a function
, which clearly is. The statement is in the create
function, it doesn't work in the other functions either.
Code:
var Game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', {create})
var question;
function create() {
question = Game.add.text(Game.width/2, Game.height/2, 'On which day is Pi celebrated?', {align: 'center'}).anchor.setTo(0.5);
question.setVisible(false);
}
Upvotes: 0
Views: 1084
Reputation: 14845
I would recommend to use phaser 3, not phaser 2/CE/... or so. Since the most documentations and informations are for phaser 3. That said, it seems to me, that your problem is two fold:
you cannot chain the all the properties/methods like this, as the comments mention it returns a different object. You would have to do this:
// like this `question` is a Text object
question = game.add.text(game.width/2,game.height/2, 'On which day is Pi celebrated?', {align: 'center', stroke:'white', fill:'white'});
// set the anchor of the `question`
question.anchor.setTo(0.5);
the function setVisible
doesn't exist for the text class. (atleast it is not mentioned in the documentation, side note: in phaser3 this function exists). For phaser 2/CE you would have to set the property visible
:
question.visible = false;
So the whole function should look something like this:
function create() {
question = game.add.text(game.width/2,game.height/2, '...', {align: 'center'});
question.anchor.setTo(0.5);
question.visible = false;
}
Upvotes: 1