Terumi Posted November 17, 2013 Share Posted November 17, 2013 Hello all, Is it possible to align a group to the center of the stage? I have a series of buttons that comprise the locked and unlocked levels of my game.Because the number of levels is arbitrary (as for now) is it possible to determine the width of the group in order to align it to the stage? Link to comment Share on other sites More sharing options...
Terumi Posted November 21, 2013 Author Share Posted November 21, 2013 anyone? Link to comment Share on other sites More sharing options...
hackenstein Posted November 22, 2013 Share Posted November 22, 2013 You could write a function that iterates through the group to determine the combined sum of the individual widths and their spacing. If all buttons have the same width and are spaced uniformly, you wouldn't even have to iterate, because you can calculate the combined with using the length of the group. en4ce 1 Link to comment Share on other sites More sharing options...
Stephen304 Posted January 28, 2014 Share Posted January 28, 2014 Is there a solution for 1 sprite? I need nametags for players and I can't have the nametags left aligned with the player sprite and the names can be any length. Link to comment Share on other sites More sharing options...
XekeDeath Posted January 28, 2014 Share Posted January 28, 2014 nameTag.sprite.x = player.sprite.x + ((player.sprite.width - nameTag.sprite.width)/2);If your name tag is a Phaser.text object, then consider wrapping the calculation in Math.Floor() to prevent some blurry text. Link to comment Share on other sites More sharing options...
Stephen304 Posted January 28, 2014 Share Posted January 28, 2014 Thanks I didn't see the width property. It works great! Link to comment Share on other sites More sharing options...
Raptisha Posted March 5, 2017 Share Posted March 5, 2017 How about this: this.groupName.centerX = this.world.centerX; this.groupName.centerY = this.world.centerY; Link to comment Share on other sites More sharing options...
Recommended Posts