How do I randomly pick objects that aren't on screen?

  • Goal: I'd like for those colored blocks to appear randomly, one at a time, on screen based on a global variable's value. Each one has a set x and y; so the position doesn't have to be random, just which one shows up.

    So for example:

    variable = 5 | one block shows up

    variable = 10 | another shows up

    etc.

    I imagine I have to use some check that looks to see "if on screen..." but other than that, I haven't figured it out correctly without having them all show up or none of them showing up. I'm going with "if on screen..." because the blocks can be destroyed and I would like for them to appear again.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 'Off screen' is not really a player in the flow. It is just a 'place' where you place those that are 'not in play'.

    I suppose you use instances, else use a family.

    Give them a instance Boolean 'InPlay'.

    When the global variable demands to bring one in play ....

    ___ Object > Is Boolean instance set 'InPlay' <--- INVERTED (so it reads as 'InPlay' = false)

    ___ System > Pick random instance (Object)

    __________action > Object > Set Boolean 'InPlay' to true

    __________Actions to place it somewhere on screen.

    When an object is destroyed.

    _________action > Object > Set Boolean 'InPlay' to false

    _________action > Object > set X to -9999

    Do not actual destroy it, just move it off screen.

    If you want to use ''Off screen' as kind of 'the Boolean' ...

    When the global variable demands to bring one in play ....

    ___ Object > Is On screen <--- INVERTED

    ___ System > Pick random instance (Object)

    __________Actions to place it somewhere on screen.

    When an object is destroyed.

    _________action > Object > set X to -9999

  • 99Instances2Go

    Thanks! Super helpful.

    One issue I'm running in to is that there is no check if an object is already in a position so it's stacking instances. Any ideas on how to go about that?

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