Random Actor Spawn RRS feed

  • Question


    Hello,  How would I make random actors spawn in one place on the scene and disappear after a key stroke or mouse click, then another random actor spawns in it's place?  What also would be great is if the actor played a sound before disappearing and the new one is spawned.



    Thursday, October 16, 2008 3:31 PM


  • If you're comfortable with code, this would be relatively easy - just create a list of actor names and use Math.random to select the one randomly. 


    Otherwise, one option would be to generate a pseudo-random choice by creating a series of behaviors which increment a property on the scene with the last one looping back to 0 and have these behaviors executing every frame.  (so the first would execute when the property is 0 and add 1 to it, the second would execute when the property is 1 and add 1 etc until the last one executes when the property is N where N is the total number of actors and sets its value to 0).  You could then have another series of behaviors with the filter set to that property to spawn each of your new actors such that when it's 0, a behavior spawns actor 1, when it's 1, the next behavior spawns actor 2 and so on.


    Make sense?

    Tuesday, October 21, 2008 12:07 AM