Jump to content

Setting Image Scale In game.sprite.add


Will
 Share

Recommended Posts

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 stars

for(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

        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

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

 Share

  • Recently Browsing   0 members

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