# Generate objects in shapes

Get help using Construct 2

### » Thu Aug 22, 2013 3:09 pm

Hi,

I was wondering if anyone here have any examples or samples on how to create objects and have them appear in certain shapes.

Like for an example, a bunch of coins appearing in the shape of squares or pyramids.

I tried playing around with 2 For loops but results were disastrous.

Any help is very much appreciated. Thank you.
B
32
S
13
G
6
Posts: 42
Reputation: 5,704

### » Thu Aug 22, 2013 3:41 pm

An array is what you are after! Are you comfortable with arrays? If not, you should read the tutorial 'arrays for beginners'.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,739

### » Thu Aug 22, 2013 4:24 pm

I just took a quick look at the Arrays for Beginners and I think I get the idea.

Will give it a try later on. Thanks!
B
32
S
13
G
6
Posts: 42
Reputation: 5,704

### » Sun Aug 25, 2013 2:28 am

I'm still having trouble with 2D array, even after following the example from the 'Arrays for Beginners'.

Does anyone have any other examples I can follow?
B
32
S
13
G
6
Posts: 42
Reputation: 5,704

### » Sun Aug 25, 2013 3:16 am

No need to use an array just use two for loops. In fact the array wouldn't help in the case of the triangle.

For a 3x3 square whose top left is at x,y do this:

Global number x=100
Global number y=30

Start of layout
For "row" from 0 to 2
For "col" from 0 to 2
--- create sprite at 32*loopindex("col")+x, 32*loopindex("row")+y

And for a triangle do this:

Start of layout
For "row" from 0 to 2
For "col" from 0 to loopindex("row")
--- create sprite at 32*loopindex("col")+x, 32*loopindex("row")+y
B
100
S
38
G
134
Posts: 5,550
Reputation: 85,313

### » Sun Aug 25, 2013 4:46 am

[QUOTE=R0J0hound] No need to use an array just use two for loops. In fact the array wouldn't help in the case of the triangle.

For a 3x3 square whose top left is at x,y do this:

Global number x=100
Global number y=30

Start of layout
For "row" from 0 to 2
For "col" from 0 to 2
--- create sprite at 32*loopindex("col")+x, 32*loopindex("row")+y

And for a triangle do this:

Start of layout
For "row" from 0 to 2
For "col" from 0 to loopindex("row")
--- create sprite at 32*loopindex("col")+x, 32*loopindex("row")+y[/QUOTE]

Thanks! Will try it out.
B
32
S
13
G
6
Posts: 42
Reputation: 5,704