Sorry if this is a stupid question but when I try to use Phaser.Utils.Array.GetRandom the browser console just says Uncaught TypeError: Phaser.Utils.Array.GetRandom is not a function
let randomSprite = Phaser.Utils.Array.GetRandom(arr);
Have you included Phaser in your index.html?
<script src="phaser.min.js"></script>
You can type ‘phaser’ in the console, and see if Phaser shows up.
Yes i have
Fixed it it seems to have had some problem with being in a custom function but before you go can i ask you another thing
I’m very curious what custom function could mess up a static call…
It was something like this
function spawn(){ arr = [0, 1, 2, 3]; for (let i = 0; i < 5; i++) { randomSprite = Phaser.Utils.Array.GetRandom(arr); a = normalChar.create(Phaser.Math.Between(0, game.config.width), Phaser.Math.Bet ween(game.config.height / 2, game.config.height), randomSprite).setInteractive(); a.on ('pointerdown', removePoint); console.log(a) }
And that didn’t work? What did you change to fix it?
Placed it in the update function and used an if statement to call it
This makes no sense at all.
If the window object knows Phaser, it doesn’t care where or how you call a static function.
I would appreciate if you could put your code that gives that error online somewhere.