divers Posted May 14, 2017 Share Posted May 14, 2017 Hello, recently I started creating simple game. I want to place 4/9/.. etc object next to each other. Something like this: [ ] [ ] or [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] I have an array with object cubes, but i dont know how to display them in order like this(for now they are all in the same place, 50,50). Code for Cube: function Cube(){ this.show = function(){ var temp = game.add.sprite(50,50, 'rect'); temp.inputEnabled = true; temp.events.onInputDown.add(onTap, this); } } Link to comment Share on other sites More sharing options...
Befive.Info Posted May 15, 2017 Share Posted May 15, 2017 Sorry if I understood incorrectly. excerpt code from my game: can it be a hint? divers 1 Link to comment Share on other sites More sharing options...
samid737 Posted May 15, 2017 Share Posted May 15, 2017 EDIT: I misread the topic, I thought @Befive.Info was asking the question and replied to add his source code... Il just leave it in case someone ever needs it. NEW ANSWER: Here is another way to do it using A nested for loop (might not be as efficient, though, but it works): boxGroup=game.add.group(); for(var i=0;i<13;i++){ for(var s=0;s<13;s++){ var object=makeBoxes(150,150,s,i); } } } function makeBoxes(x,y,s,i){ this.sprite=game.add.sprite(x+s*40,y+i*40,'boxes'); boxGroup.add(this.sprite); return this.sprite; } Applied to an example: OLD ANSWER(ALREADY ANSWERED BY @Befive.Info): You can make a custom sized grid by generalizing block building to a procedure with input arguments. Here is an example of what you could do: It is just A procedural approach to your box building. So you just do the exact same procedure for your other blocks, but you change the row size and keep a count of the row index. You could build the boxes as seperate groups (you have one parentgroup currently) via the procedure, so that you can customize the position of the group to your will. You could also just simply add an if statement that checks the element in the _keyNames: if(isAnumber(_keyNames[key])){ _each_row_has=4; }else{ _each_row_has=8; } function isAnumber(n){ //some function that checks if it is a number } But the indexing will fail in this case (positions relative to letters won't look nice). divers 1 Link to comment Share on other sites More sharing options...
divers Posted May 15, 2017 Author Share Posted May 15, 2017 Quote Thank your both very much! Link to comment Share on other sites More sharing options...
Befive.Info Posted May 15, 2017 Share Posted May 15, 2017 @samid737 Thank you for sharing your insight Link to comment Share on other sites More sharing options...
snowbillr Posted May 15, 2017 Share Posted May 15, 2017 Take a look at http://devdocs.io/phaser/phaser.group#align too. I'm using that to arrange bricks in a breakout clone and it's working very well. Befive.Info 1 Link to comment Share on other sites More sharing options...
Befive.Info Posted May 16, 2017 Share Posted May 16, 2017 @breed Thank you! That is really easy. I do not need any calculations by using the method. Quote parentGroup.align(8, 4, 100, 100); That single line takes care of the rest. All I have to do is to place the tiles in order. Link to comment Share on other sites More sharing options...
Recommended Posts