How do I spawn sprites in a random order?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Cute cartoon girl character with Walk, Jump, and Idle animations for 2D games.
  • Hi Folks,

    I'm working on a simple drag and drop game whereby the user matches pairs of socks on a washing line:

    I'm using pre-placed spawners (orange circles) to then generate pairs of socks on start of layout. However, I'm really struggling to get it to execute properly without the socks overlapping each other (multiple socks spawning on the same location):

    This is the current version of code that generates the above result:

    [Spawn Socks]

    ----+ System: Every tick

    --------+ System: Sock1Count < 7

    ------------+ System: Pick a random Spawner instance

    -------------> Spawner: Spawn sock1 on layer 0 (image point 0, create hierarchy: False, template: "")

    -------------> Spawner: Destroy

    ----+ System: Every tick

    -----> (no actions)

    ----+ System: Sock2Count < 7

    --------+ System: Pick a random Spawner instance

    ---------> Spawner: Spawn sock2 on layer 0 (image point 0, create hierarchy: False, template: "")

    ---------> Spawner: Destroy

    Any help would be appreciated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's a lot easier to manually place all socks on the layout, and then just randomize their images (animation frames). Say, you can make them initially invisible, and turn visible after you assign frames to them.

    For "p" from 0 to 11 // number of pairs
    
     Repeat 2 times
     Sock is NOT visible
     Pick random Sock instance 
     -> Sock set animation frame to loopindex("p")
     -> Sock set visible
    
  • Such an elegant solution, thanks so much, works a treat!

    Just needed to add a 'stop animation' action.

  • Just needed to add a 'stop animation' action.

    Better set animation speed to 0 in the animation editor.

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