How to limit the number of object in a layout?

0 favourites
  • 6 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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

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

    <img src="http://www.infinitepossibilitygames.com/demos/maxenemy/maxenemy.png" border="0" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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

    Cheers

  • 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 <img src="smileys/smiley16.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)