Random actor spawn after one gets destroyed.
mrajfleming
Member Posts: 1
I'm very new to GameSalad, as of right now I'm just learning some of the basics. One thing I'd like to do in a basic game I'm making for the sake of learning is have coins spawn in a random spot on the scene as they are collected.
Example: There is a Player and Coin actor
-Player and Coin are initially visible (can you make an actor [coin in this case] appear in a random location when loaded?)
-Player navigates and collides with coin
-Coin gets destroyed, Coin count (Score) goes up one
-Another coin is generated in a random spot when previous coin is destroyed.
I hope that made sense. I'll clarify as best as I can if it didn't. I've gotten down how to control the "player" with the keyboard (i.e. WASD) and how to make the "coin" get destroyed when the "player" collides into it, as well as how to make the "coin count" increase, but I don't know how to make another coin respawn in a random location.
Any help is appreciated, thanks!
Example: There is a Player and Coin actor
-Player and Coin are initially visible (can you make an actor [coin in this case] appear in a random location when loaded?)
-Player navigates and collides with coin
-Coin gets destroyed, Coin count (Score) goes up one
-Another coin is generated in a random spot when previous coin is destroyed.
I hope that made sense. I'll clarify as best as I can if it didn't. I've gotten down how to control the "player" with the keyboard (i.e. WASD) and how to make the "coin" get destroyed when the "player" collides into it, as well as how to make the "coin count" increase, but I don't know how to make another coin respawn in a random location.
Any help is appreciated, thanks!
Comments
Do you want the easy way or the hard way?
EASY WAY
Recycle the coin actor. On your coin actor, add a rule that says:
When actor collides with actor [player]
.....Change Attribute self.position.X to random(0,1024)
.....Change Attribute self.position.Y to random(0,768)
If you click the expression editor (the little 'e' symbol) for the x and y position of the spawn actor behavior, you can either type in or select the random function from the drop-down menu. 1024 and 768 are iPad maximum dimensions, but you can adjust as necessary.
HARD WAY
On your coin actor, you'll need a rule that says:
When actor collides with actor [player]
.....Change Attribute game.readyToSpawn (type: boolean; set to false initially) to true
.....Timer after 0.1 seconds
..........Change Attribute game.readyToSpawn to false
.....Destroy actor
Make a coin spawner actor and add this rule:
When attribute game.readyToSpawn is true
.....Spawn actor [coin] at random(0,1024) random(0,768)
The 0.1 timer is just a bit of a hiccup to allow the spawner to catch the change in that boolean value from false to true (and then back to false to wait for the next coin to be destroyed).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Welcome to gamesalad!
The only thing I'm having trouble with is the initial spawn and respawn of the 'coin' actor using the -easy- method. Any elaboration would again be much appreciated.
Thank you!!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User