Jump to content

Group Positioning


Recommended Posts

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

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.

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.


  • Recently Browsing   0 members

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