How do I count # of sprites in all layouts

0 favourites
  • 9 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • Hello. I wonder if the count can count sprites in all layouts AND/OR in layout which player is not at the present.

    For example if my game has 100 levels and I´d like to show how many stars to collect in each level. Could the game count those stars in each layout (player can revisit layouts and collect stars the missed first time. Stars have persist behaviour).

    I wonder if count function has somekind of way of doing this. I am sure it could be done other ways but it might be too heavy since there are many levels?

  • You just use a global variable that starts at 100 for the total. You can use a global variable for each level that has a stars total. When one is collected you subtract 1 from the total and the level total.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You just use a global variable that starts at 100 for the total. You can use a global variable for each level that has a stars total. When one is collected you subtract 1 from the total and the level total.

    Yes. This is the answer to total number but for each levels... that needs a different solution. Maybe I just leave it if the count function can only count in one layout as there is not stars.count(layoutname) kind of function I suppose.

  • "You can use a global variable for each level that has a stars total." You just make a global variable for each level, level1_starcount, level2_starcount. Assuming you know the amount of stars and in what level and they are not procedurally generated or something. You just set level 1 to 5, level 2 to 5, total is 100 etc. Then when you collect a star in level1 you subtract 1 from level1_starcount and the total.

  • Ok. I guess the answer is that count function only works at the current layout. That solution you gave could be useful. Thanks.

  • They are global variables, you can access them any time. Just be sure to 'include' the event sheet that contains them.

  • Just realized that it would make a heavy code since every time player grabs a star the game needs to know at what layout it´s running (on one event sheet).

    Maybe array could solve the heaviness.

  • Then you assign the stars a variable for what level they're in. I'm pretty sure you only need variables here, no reason for an array, unless you want to explain exactly what you're doing.

  • Then you assign the stars a variable for what level they're in. I'm pretty sure you only need variables here, no reason for an array, unless you want to explain exactly what you're doing.

    That´s actually a very good idea! Thank you again!

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