How to limit the number of object in a layout?

Get help using Construct 2

Post » Wed Mar 06, 2013 11:06 am

I've been working on my new project and stuck in this problem
so, I don't know if this have been asked before (I couldn't find it), how can I limit the number of object inside the layout?? or more specific, inside the screen?

the idea is every x second enemy is spawned, and as long as not destroyed, they remain there, chasing the main character, and attack. And if we play long enough, the number of enemies will be awful.

I come up with an idea to limit it using variable, so it won't spawn unless the variable is not met. But it will take time if I have various type of enemy and limit them for each type. Maybe there's another way?? simpler way to do it

thanks in advance
B
12
S
3
G
4
Posts: 56
Reputation: 3,235

Post » Wed Mar 06, 2013 12:02 pm

Add a condition to your every x seconds that checks the count of your enemy sprite like so:

B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Wed Mar 06, 2013 1:18 pm

@theubie thanks for your advice, but can you please explain it a little bit more? because I can't find how to count the enemy sprite
B
12
S
3
G
4
Posts: 56
Reputation: 3,235

Post » Wed Mar 06, 2013 1:30 pm

Every sprite has a .count expression. Assuming you have one sprite for your enemy, and that enemy sprite is named Enemy, then the expression to find out how many enemy sprites you currently have in your game is:

Enemy.Count

If you use the System event: Compare two values you can compare the Enemy.Count expression with however many sprites you want to limit in your game to see if you are under that amount.

The screen shot I posted is exactly what you would have in Construct 2 to figure this out.

If you have more than 1 enemy sprite you're wanting to check on you've got two options:

Place all your enemy sprites into a family and then use that family's .Count expression.

Or you can add all the .Counts from each sprite (Enemy1.Count + Enemy2.Count + Enemy3.Count) in the compare value event.

The family method is better IMO as families make your life better in general.

For more info on common expressions see this manual entry.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Wed Mar 06, 2013 1:34 pm

What Ubie wanted to say is that ...

you always need to verify that the count of an object is less than what you wanted , here , ubie did set the max count to 10 via a variable ( MaxEnemies ) and did compare it to the number of redsquares in the game

He didn't stop spawning them until the number of the redsquares reached
10

P.S: The expression to find the number of said objects is
*Insert-Object-Name-Here*.count

CheersWhiteclaws2013-03-06 13:35:08
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Wed Mar 06, 2013 1:38 pm

@theubie
oh silly me, I didn't see the screenshot before, somehow it doesn't appear last time I here.
thanks a lot, man
I forgot about it completely lol

@Whiteclaws
thanks for the attention and the explanation
I somehow forgot it (I've read it in manual before)
and somehow the screenshot doesn't appear last time
thanks anyway

really appreciate your help guys r4dicaldreamer2013-03-06 13:43:30
B
12
S
3
G
4
Posts: 56
Reputation: 3,235


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, jul, nicklowkcmagic and 18 guests