How do I create random instances?

Get help using Construct 2

Post » Thu Mar 19, 2015 7:03 pm

I want to create random instances but with some rules :
1- instances should be the same copy of the original object (no change in size).
2- instances have the same Y value (raw of instances).
3- X value of each one should be the multiply of the instance width (for example 160 pixel).
4- no 2 instances should be created overlapping each other.

the result of that should be a raw of instances at certain positions arranged randomly like this for example
(instance - space - space - instance - instance - instance - space - instance - space - space - space - instance) etc.
each instance and each space should have the same width and aligned to each other.

in the game I'm working on I'm creating columns passing the screen (scrolling) and destroyed when they become outside the layout as they left the right side of the screen, but i need them random.
i tried using "choose" like this :
if instances count < 2 ---------> create instance at : y=240, X= Choose (160,320,480,640)

but it didn't work as i want, C2 may create 2 instances on each other.
I'm not familiar with arrays and still trying to understand them, so for now what can i do to achieve this ?
thanks
B
15
S
5
Posts: 192
Reputation: 1,514

Post » Fri Mar 20, 2015 12:45 am

There's a couple of ways to go about it. Here's my take on it if I understand you correctly. There is no reason an instance should change size when it's created.

Create a small sprite called SpawnBox and set it's property to invisible

System> Every 2 seconds
if instances count < 2 > System > Create Object > SpawnBox at : y=240, X= Choose (160,320,480,640)

Create a dual condition with (X) being inverted

SpawnBox > On Created > SpawnBox ...... > Spawn Instance
instance > On Overlap (x) with Instance ... > SpawnBox Destroy

Else > SpawnBox Destroy
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Fri Mar 20, 2015 3:25 am

Thanks for help, i don't know if you got the idea or not, and I'm sorry for my poor language :)
the attached image shows what i mean : randomly arranged columns but at certain positions, the distance unit is the instance width or the multiply of it.
so the generated columns may be : adjacent (space = 0) or away from each other by the instance width (160 pixel for example) or away from each other by 160*2, 160*3, 160*4 etc.
the adjacent columns may be 2 of them or three or four.
same thing for spaces, 2 adjacent spaces units may be or three or four.
randomly but with some rules.
hope i explained it correctly this time :) and many thanks for your reply.
You do not have the required permissions to view the files attached to this post.
B
15
S
5
Posts: 192
Reputation: 1,514


Return to How do I....?

Who is online

Users browsing this forum: marcoscodas and 8 guests