GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

howto Spawn random actors?

guru-at-zidwareguru-at-zidware Posts: 369Member
HI..working on a quiz of sorts and wanted to spawn random actors, say from a list of 50? Any thoughts?

John

Comments

  • PixelRyanPixelRyan Posts: 17Member
    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 Posts: 256Member
    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 Posts: 10,380Member, Sous Chef
    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 Posts: 256Member
    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 Posts: 369Member
    ok..great let me try that..!
This discussion has been closed.