howto Spawn random actors?

guru-at-zidwareguru-at-zidware Member Posts: 369
edited November -1 in Working with GS (Mac)
HI..working on a quiz of sorts and wanted to spawn random actors, say from a list of 50? Any thoughts?

John

Comments

  • PixelRyanPixelRyan Member Posts: 17
    I was wondering about spawning random patterns in my game, here is what I ended up with, not sure if its the best way. Make an integer attribute named Random Number. Do a change attribute rule and change Random Number to "random(1,50)" to pick a number 1-50. Then when you want to spawn something from the list of 50 have a bunch of rules checking for if random is equal to 1 then spawn this one, etc.,etc.,
  • StormtrixStormtrix Member Posts: 256
    Take a look at these tshirtbooth demos -- this is what i use as a foundation for randomizing things.

    http://gamesalad.com/game/1621

    http://gamesalad.com/game/1627
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    yea, do exactly what pixelRyan said, pick a random number, and then have rules that say

    if number = 1
    spawn actor1

    if number = 2
    spawn actor2

    but, to keep memory down, you're better off hiding all the actors offscreen, and then MOVING them into the camera's view depending on the number, spawning and destroying is very taxing on memory
  • StormtrixStormtrix Member Posts: 256
    Or if you are just spawning one actor out of the 50
    Then you could do what I did for my one card poker game.
    Create just one actor to spawn an in the actor
    Have this. Create an integer attribute called something like random

    Change attribute. Self.random to random(1,50)

    Change attribute. Self.image to floor(self.random)..".png"

    Just name all your images like 1.png, 2.png etc.
  • guru-at-zidwareguru-at-zidware Member Posts: 369
    ok..great let me try that..!
Sign In or Register to comment.