How do I align an army of created objects?

  • Hey people of the Scirra World!

    I need help on something that has been troubling me.

    First, I'll tell you a little about my game; then the problem.

    I have a Character that spawns (System | Create Object "MAN") on a certain X & Y position when a button is clicked. He, and all his clones move according to the stance global variable, so if the stance is forward, all the MEN move forward with Simulate Platform pressing Right, if the stance variable is Idle, all MEN stay in the spot they were before.

    Problem is, how do I align these MEN to a new Column of 5, then after that a new row?

    Much like this:

    I can't figure out a way to code this since I'm sort of new with Construct, but a decent coder in Java.

    I'm thinking maybe something like when I click a button called "organize", the MEN align in one column, in which they're each 3 pixels down each, and after 5 men are in one column, the other men move to the next row.

  • To create one row:

    Create a global variable Yspawn

    on button pressed

    system set Yspawn to the Y-coordinate of the first man to be created

    -- system repeat 5 times

    system create man at x= 200 y = Yspawn

    system add 3 to Yspawn

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That only aligns them when they're being spawned/created.

    I was looking for an approach for which the MEN (already created) align themselves when you press a button.

    Maybe I can use an array approach for the columns and rows, but what variables would I need to use for each created MAN?

  • Well first you should pick one of the men to use as a starting point..

    I will give it a boolean variable Startingpoint for this example

    Also I'll add a boolean variable IsSorted

    also I wil use two global variables StartingpointX and StartingpointY

    on button pressed

    ----men is startingpoint

    system set startingpointX = men.x

    system set startingpointY = men.y

    men set IsSorted to true

    -- system repeat 5 times

    ---- pick all men

    ---- men Issorted is not true

    ------- men pick nearest to startingpointX, startingpointY

    men set position to startingpointX, startingpointY+3

    men set IsSorted to yes

    system add 3 to startingpointY

    easiest way would be to create a function for this and call it with an action.

    comparing if men.count is not the same as the number of men with IsSorted is true

    After the repeat 5 times you could subtract from the startingpointX to get to the new row of men.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)