Spawning one actor at a time.

Hi guys, just started Gamesalad 3 days ago and i think am doing pretty good so far. i am working on a game that spawns 4 balls from the top and fall down. each ball has a different speed. the goal is to collect the balls before they hit the ground. currently i have 4 spawners, each with a timer and spawn behavior. its working fine but the problem is that sometimes i get 3 spawns at the same time and its impossible to catch the 3 balls. i want to make it in a way that it leaves time between each spawn of random actors (balls) maybe connected spawn behavior for the 4 balls. so for example i have 4 spawn actors (balls) red black blue green. red spawns wait 1 sec blue spawn wait 1 sec, black spawn wait 1 sec blue spawn wait 1 sec an so on.

Appreciate the help. thnx

Best Answer

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    Instead of 4 spawners, use a single spawner. Use a timer to determine when to spawn (e.g. every 1 second or at random times with a custom timer). Inside of the timer, choose a random value (Change Attribute game.randomNum to random(1,4)) and then spawn a specific ball color at a specific location based on that value.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • jcheikhajcheikha Member Posts: 8
    Great thnx alot, works perfect. but now the spawn rate is very slow, how can i make it faster. something the more time that passes the faster the spawn is?
  • ktortiktorti Member Posts: 27
    This video might help:
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2014
    You can change the timer to whatever you want, such as every 0.1 seconds.

    If you want the timer to "speed up" so that it first spawns every 5 seconds, then every 3 seconds, etc. you have to use an inverse proportion which I describe here, although in a different context. Or you can just decrease a timeStamp like this:

    [Create real attributes called game.timeStamp and game.spawnDelay. Set game.spawnDelay to some number of seconds such as 5.]

    When attribute game.Time ≥ game.timeStamp + game.spawnDelay
         Spawn actor
         Change attribute game.timeStamp to game.Time

    Timer every 10 seconds
         Change attribute game.spawnDelay to max(0,game.spawnDelay-1)


    That will make it so that an actor spawns every 5 seconds to begin with and then every 10 seconds the delay will decrease by 1 and start spawning every 4 seconds, every 3 seconds, etc.

    There are also other ways to achieve this using mathematical functions.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jcheikhajcheikha Member Posts: 8
    thnx for the video Ktorti, i have done the same thing. but what i was wondering is for example, i start with a timer of 3 sec per random spawn and each 10 seconds pass by the spanw time decreases. so something like, spawn time 3s after 10 sec 2.9s after 10 sec 2.8s after 10 sec 2.7s
  • jcheikhajcheikha Member Posts: 8
    edited February 2014
    i followed your steps exactly but for some reason am not getting a spawn.
  • jcheikhajcheikha Member Posts: 8
    edited February 2014
    this is my rules, http://s16.postimg.org/ymoc85ch1/code.png
    Stamp = 0
    Delay = 5
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2014
    You
    i followed your steps exactly but for some reason am not getting a spawn.
    Sorry! That's what I get for trying to do this quickly and from memory. It should have been:

    When attribute game.Time ≥ game.timeStamp + game.spawnDelay
         Spawn actor
         Change attribute game.timeStamp to game.Time

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jcheikhajcheikha Member Posts: 8
    I appreciate your help but thats not working either :(
  • ktortiktorti Member Posts: 27
    You're going to need an exponential formula of some type. Unfortunately I don't know enough about formulas to help you out.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2014
    Made you a demo with the same rules I posted above.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jcheikhajcheikha Member Posts: 8
    thnx for the help, this is driving me crazy, did the exact thing you did in the demo and i still dont get a spawn, but i get the timer count down :s
  • jcheikhajcheikha Member Posts: 8
    hey tatiang can you please check out my code and see if you can figure out why its not spawning the actor? here is the link to download the file. http://speedy.sh/hQ6dP/sample.rar
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    In your spawner actor, you have the position of the spawned actor set to x=0 and y=275, relative to scene, so it's always going to spawn there (at 0,275). I'm using Mac Creator and I see the actor spawn each time on the edge of the screen in the same place every time.

    What you probably want is to change those values to x=0 and y=0 (or maybe -50... something like that) relative to ACTOR.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jcheikhajcheikha Member Posts: 8
    edited February 2014
    hmm i don't want it to be relative to the actor, coz then it will only spawn under the actor. i want it to spawn from anyplace in the top. so basically i will have like 10 clouds moving right and left and actually only one spawning balls but the balls will spawn from different location each time in the sky. which will make it look like its raining balls, starts slow then increase in speed.
Sign In or Register to comment.