How do I make objects spawn on grid?

Get help using Construct 2

Post » Thu Sep 05, 2013 7:40 am

I have multiple objects falling down from the sky at different rates. However, I never want one to overlap or spawn on the other and always want them fall in a moving grid. For example, imagine something like a tic-tac-toe board on a 20 x infinite grid and there are Xs and Os scattered throughout.

I'm using "Create object" to spawn objects and "Bullet gravity" to set speed.
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Thu Sep 05, 2013 7:59 am

The way I make grids, is to set the position in intervals of 20 (or any number you want), using this:

Sprite;
> Set X to : (round(Sprite.X*0.05))*20
> Set Y to : (round(Sprite.Y*0.05))*20

B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Post » Thu Sep 05, 2013 8:16 am

Hmm... the objects are now spawning not from the sky but from the last object and also don't randomly spawn along the X axis.
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Thu Sep 05, 2013 8:24 am

Wait I think I got it:

X: random(100,600)
Y: -250
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Thu Sep 05, 2013 8:29 am

Darn. too systematic for the last code i put in. I need it to randomly spawn in any of the grid buckets and not just the same distance each time.

X and Y between ranges but within grid
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Thu Sep 05, 2013 8:52 am

[QUOTE=Sargas] The way I make grids, is to set the position in intervals of 20 (or any number you want), using this:

Sprite;
> Set X to : (round(Sprite.X*0.05))*20
> Set Y to : (round(Sprite.Y*0.05))*20

[/QUOTE]

What about this for Y?
random(round(-100*0.05)*150,round(-600*0.05)*150)
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Thu Sep 05, 2013 9:34 am

Set X to : round(sprite.X/gidsize)*gridsize

So for a 32 grid: round(sprite.X/32)*32 . YOu can use the same formula for snapping stuff to the Y axis too.

To make them "fall" on grid increments, use a move +Y:gridsize

Any other movements, have only at the gridsize, and it should never need to be set on the grid again.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Nicolas951, tarek2 and 9 guests