function randArray(arrayName) {
arln = arrayName.length;
arst = arrayName[Math.floor(Math.random() * arln)];
return arst;
}
create: function(){
//starts physics engine
game.physics.startSystem(Phaser.Physics.ARCADE);
player = game.add.sprite(width/2, height/2, 'player');
randSpawnItem = game.add.sprite(10, 10, randArray(randItem));
randSpawnItem2 = game.add.sprite(50, 50, randArray(randItem));
So the randArray function works, and there is nothing wrong with the create. I'm using Phaser, and I'm trying to spawn items randomly (kind of like in Binding of Issac.) I forsee a problem in the future, when I'm detecting for collison, I need to know what item spawned to give the right kind of item to the player. How would I get that third attribute of randSpawnItem
or randSpawnItem2
, or is there another way to go at this completely? Sorry if that's a noobie question! Didn't know how to word it and didn't find it anywhere else. Thanks in advance for your time.