Jump to content

Group Positioning


sinanqd10
 Share

Recommended Posts

I want to generate a group which display dynamically in order and give a little bit margin right.

eg: In the game world, It will generate 1 little space 2 little space 3 little space 4 etc...

What method should I use?

Can anyone please guide me?

Thanks in advance.

Link to comment
Share on other sites

Here it is:

var groupWinLoseDraw;var f;var myGame = {     preload: function() {          this.game.load.spritesheet('sprite123','assets/sprite123.png',30,10);          this.game.load.spritesheet('button','assets/button.png',40,20);     },     create: function() {          groupWinLoseDraw = game.add.group();          f = groupWinLoseDraw.create(200, 30,'sprite123');                   var btn = game.add.button(300,400,'button',this.button,this,0,1);     },     button: function() {          f.frame = game.rnd.between(0, 2);      }}

This code will output the sprite,but what I wanted to dynamic increase the x position like I mentioned above;

 

eg: 1 space 2 space 3 etc...

Link to comment
Share on other sites

If your sprites are numbered in sequence (starting at sprite0), try this in your create function...

create: function() {  var totalSprites = 10;  var groupWinLoseDraw = game.add.group();  var space = 50;  var spriteWidth = 200;      for(var i=0; i<totalSprites; i++){    var positionX = (i*spriteWidth) + (i*space);    groupWinLoseDraw.create(positionX, 30,'sprite'+i);  }},
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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