Randomly spawning actors

bloodandtreasurebloodandtreasure Member Posts: 1
edited November -1 in Working with GS (Mac)
We have actors descending on the screen that when pressed, spawn other smaller actors. In other words, the larger actor breaks up into smaller actors when clicked.

How do you spawn a random variety of smaller and different actors from one larger actor?

Thanks in advance for any help.

Comments

  • synthesissynthesis Member Posts: 1,693
    Spawn the actor.
    Then in the actor...set alpha to 0 as the first behavior.

    Then have a group of change attributes that generate random values...
    Example:
    self.position.X = random(0,320)
    self.position.Y = random(0,480)

    then after you have all of the "random default" or "standard default" setup settings completed...

    change the alpha to 1
    and the flip a boolean such as:
    self.actorReady = TRUE

    Then when self.actorReady is TRUE...
    start all your actor rules.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Also, to spawn the random variety: say you have 5 smaller actors to choose from, and you want 10 randomly spawned from that selection:

    Global attribute called SpawnAmount, for instance. Set SpawnAmount to 10. In a Rule, if SpawnAmount >0 then random(1,5); if 1, then spawn actor 1, if 2 then actor 2, etc. Not tested, but think that should work. Then the random positions as synthesis suggested. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • synthesissynthesis Member Posts: 1,693
    Another means would be to use a "seed" actor.

    Basically its a transparent actor on the stage that moves around when the main actor asks it to spawn a new "creature".

    So...main actor:
    when pressed = create new creature = true

    Then the seed actor (on TRUE) goes to a random location and then chooses a random seed value...like this:

    rule:
    when game.createNewCreature = TRUE
    self.X = random (1,320)
    self.Y = random (1,480)

    self.newCreatureType = random (1,10) [ or however many you want]
    self.spawnNewCreature = TRUE
    game.createNewCreature = FALSE (shutoff of part 1)

    then...
    when self.spawnNewCreature = TRUE >>
    when self.newCreatureType = 1
    ----- spawn creature1 at self.position.X and self.position.Y
    ----- self.spawnNewCreature = FALSE (shutoff of part 2)

    when self.newCreatureType = 2
    ----- spawn creature2 at self.position.X and self.position.Y
    ----- self.spawnNewCreature = FALSE (shutoff of part 2)

    repeat for all creature types.

    If you want to create some creatures more often than others...integrate probability.
    Here a tip on that topic:
    http://www.gsproforum.com/viewtopic.php?f=17&t=99

    Hope this gets you going!!!
    -Syn
  • ValanValan Member, BASIC Posts: 410
    There seem to be so many ways to do this.

    Here's another:
    The sub actors spawn from the parent actors when pressed.
    So there are two actors Parent actor and Sub actor
    Use the parents position and add a randomness to it.

    When Parent actor is pressed

    Spawn behavior:
    Sub actor
    x = random(-25,25)
    y = random(-25,25)
    Relative to Actor

    A very simplistic version.
Sign In or Register to comment.