Jump to content

Random name generator


donpink
 Share

Recommended Posts

I would like the name of the character to change at each death.

 

How could i pick up, randomly, a name from a self made list ?

 

this.rng = Phaser.RandomPROBLEM("ABY", "ALEX", "AL");

 

var name = this.game.add.text(-405, -20, this.rng, this.styleMalin);
this.mainGroup.add(name);
Link to comment
Share on other sites


I think Phaser might have some built in stuff for some of what you want to do, but I'm not sure.   However, pure JavaScript will do fine for this.  You can stick the names in an array and then generate a random index into that array from which to pull one.  Off the top of my head (warning, code is untested):

 


var nameArray = ["Moe","Larry","Curly"];

var randomIntInArrayRange = Math.floor((Math.random() * (nameArray.length -1)));

var randomName = nameArray[randomIntInArrayRange];

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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