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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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