spawn on press of button
Bowhill Games
Member Posts: 191
There is obviously something stupid that i am missing i am hoping someone can point out my stupidity.
I have a button that on press i am spawning multiple objects at different locations, the issue is only the first spawn rule seems to trigger which seems crazy as other actions in the same rule work (after all the spawn rules)
I have tried deleting the behaviour and recreating with no joy.
(site currently under construction)
Comments
The "When Touch is Pressed" rule condition is only true in the moment that the actor is clicked/tapped. So if you have something quick like a Change Attribute behavior, it will always complete that behavior but if you have something lengthy like several Spawn Actor behaviors, Timers, Loops, etc., then it won't have time to complete them -- unless the player holds down the click/tap for that long.
The easiest solution is to wrap everything inside of an After 0 Seconds Timer with "run to completion" checked. Run to completion ensures that behaviors complete even if their rule condition becomes false.
Another solution is to do something like this:
When Touch is Pressed
Change Attribute self.startSpawning to true
When attribute self.startSpawning is true
Spawn Actor
Spawn Actor
Spawn Actor
etc.
Keep in mind that with this second method, you would need to manually reset the value of self.startSpawning to false at some given time (e.g. with an After ___ seconds timer) to allow it to happen again with the next click/tap.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User