Will Posted September 28, 2013 Share Posted September 28, 2013 Sorry for all the questions, but... I am making a star field for my game, it will be all parallax and awesome. But, I am currently using a for loop to add all the starsfor(var i = 0; i<1000; i++) { star = game.add.sprite(Math.floor((Math.random()*800)), Math.floor((Math.random()*600)), "star"); } Which works quite nicely! Though, I would like some variance in the stars size, so some appear distant and some close. How would I do that? Also, how would I set a layer? Link to comment Share on other sites More sharing options...
Hsaka Posted September 28, 2013 Share Posted September 28, 2013 var scale = 0; var layer1 = game.add.group(); var layer2 = game.add.group(); for (var i = 0; i < 1000; i++) { var star = layer1.create(Math.floor((Math.random() * 800)), Math.floor((Math.random() * 600)), "gems"); scale = game.rnd.realInRange(0.2, 1); star.scale.x = scale; star.scale.y = scale; star = layer2.create(Math.floor((Math.random() * 800)), Math.floor((Math.random() * 600)), "gems"); scale = game.rnd.realInRange(0.2, 1); star.scale.x = scale; star.scale.y = scale; }Something like this? Link to comment Share on other sites More sharing options...
Will Posted September 28, 2013 Author Share Posted September 28, 2013 Ah, thanks! I meant, like, render layers. So, if the player were 1, and the star were 2, the player would be above the star... Link to comment Share on other sites More sharing options...
Hsaka Posted September 28, 2013 Share Posted September 28, 2013 Oh sorry. Then you could put all of your stars in the layer1 group and your player sprite, enemy sprite etc. in the layer2 group to achieve the same thing. Link to comment Share on other sites More sharing options...
Will Posted September 28, 2013 Author Share Posted September 28, 2013 Oh sorry. Then you could put all of your stars in the layer1 group and your player sprite, enemy sprite etc. in the layer2 group to achieve the same thing.Oh, ok. Thank you! Er, how would I write logic for an individual star? So if it were to go over the screen edge, it will kill itself. Link to comment Share on other sites More sharing options...
rich Posted September 29, 2013 Share Posted September 29, 2013 star.events.onOutOfBounds.add(resetStar, this);Then create a function called resetStar - the first parameter it will be given is the star sprite, so just reset it. Link to comment Share on other sites More sharing options...
Recommended Posts