Spawning one actor at a time.
jcheikha
Member Posts: 8
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
Appreciate the help. thnx
Best Answer
-
tatiang Posts: 11,949Instead 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
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
Stamp = 0
Delay = 5
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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