How do I align an army of created objects?

Get help using Construct 2

Post » Wed May 20, 2015 5:41 am

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:

Image

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.
B
4
Posts: 15
Reputation: 226

Post » Wed May 20, 2015 7:54 am

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
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed May 20, 2015 8:52 am

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?
B
4
Posts: 15
Reputation: 226

Post » Wed May 20, 2015 9:10 am

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests