how to spawn and destroy spawned actors
sswisehaupt
Member, PRO Posts: 76
How do I have a actor when touched spawn a different actor to screen and also to a table. My intension is when a player touched an actor it will spawn the same actor as many time as the player would like. Then later in the game the player can delete that spawned actor. I think that is why I need to have my spawned actors spawn to screen and also to a table.
Comments
You would use When Touch is Pressed, Spawn Actor. How does the player delete an actor that has been spawned? By clicking/tapping on it or some other way?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
When he drags it over another actor it will be destroyed. When I spawn actor, how would I save it to a table. The player can spawn as many as he wants and drag them around the scene. I need to be able to save each spawned, even when going from scene to scene. Then be able to have only one of them destroyed and removed from the table when the player decides.
If you use a collision rule to destroy an actor, then there's no need for storing any data in a table. However, if you need actors to remain after changing scene, then my demo will show you how to do that: http://forums.gamesalad.com/discussion/comment/509194/#Comment_509194. It doesn't use tables though tables would be the way to go if you're spawning a bunch of actors.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
And this demo shows one way to keep track of which spawned actor is which. Instead of using their age, you could store their x and y position. You wouldn't use a loop for your example, but hopefully having these demos will give you a way to combine them into what you need.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I would be spawning a bunch of actors. and yes I would need to have actors remain after changing scenes.
Thanks. Will try. I'll Keep you informed
unable to have it work properly yet
When you're ready, post what you have and we'll see if we can get it working.
You can upload screenshots or project files to a file-sharing site and then post the download link(s) here.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
just got your note. I will get that to you today. Not able to send this am, will send this pm. thanks so much.
Here is the file. the last screen is where I'm having problems. I haven't yet added some scenery yet. What I want to ultimately happen is: When Dec Gift spawns Tree Gift I want to player to be able to move Tree Gift around. Then when the player leaves the scene and comes back, I want Tree Gift to be in the positions where the player moved them to.
not sure if file got attached on your end????
No file.
Also @tatiang is unlikely to sift through thousands of posts in hundreds of reasonably current threads looking for posts where someone might have replied to him . . . you need to tag him like this: @tatiang - so that he gets an alert that he has had a reply.
Thanks, @Socks.
@sswisehaupt Note that you'll need to upload screenshots or project files to a file-sharing site first and then post the download link(s) here.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
By the way, here's a demo that shows how to retain spawned actors' positions after changing scenes: http://forums.gamesalad.com/discussion/comment/509194/#Comment_509194.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang here are two screen shots of my rules for my spawned actor.
https://www.dropbox.com/s/xwce6pp8kbqnrcd/Screenshot 2015-02-03 16.44.02.png?dl=0
https://www.dropbox.com/s/3lfwkbiuetp76sw/Screenshot 2015-02-03 16.40.56.png?dl=0
I'm not sure what I'm looking at there... is this based on my demo?
The Save Table behavior should be inside the Touch is Released rule, by the way. And I'm not sure about the last Change Attribute in the second image but if you have a behavior outside of a rule, it runs immediately and only once.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang I believe so. I have changed things around and used other responses to try and make it work for me, but haven't had any luck yet.
@tatiang I am not able to make it save. when I leave the scene and come back to it my spawned actor is gone. I need it to save as many spawned same actor as needed
Did you fix the location of the Save Table behavior? I went ahead and modified my demo to use a table, in case that's helpful.
I think that troubleshooting this back and forth on the forums might be very time-consuming. If you want to, you can upload the project file to a file-sharing site and then post the download link here. I don't have a ton of time but if it's a simple fix, I can let you know.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang I did. I'm sure I just must have something misplaced. Let me check out your new demo tonight and see if I can get it working. If not, I will upload it to you tomorrow and if you get a minute or so to look it over I would be very appreciative. Thanks
@tatiang HELP I am attaching my project for you to look at. The last scene is where I need help. The red gift will spawn a different red gift when player touches it. I will spawn as many time as the user touches it. I need them to be saved on the scene if the player leaves that scene. When the player comes back to this scene, he should be able to move them around and then have saved in the new spot.
https://www.dropbox.com/s/k51le1oyqzeuwz6/Santa's Gifts.gameproj.zip?dl=0
You've set up the position saving correctly. But you'll need an actor to loop over the game.Table 1 table and spawn an actor for each row using the saved position values. It looks like you tried several methods in your Respawner actor. It should be set up this way (the screenshot only shows the X position but the Y position would be similar):
The other thing you're missing is an Add Table Row behavior in your spawned actor. Without that, the data gets replaced when you spawn another actor.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang Thanks much. Will try.
Actually, the Add Row behavior should probably go in the spawner actor and then you could change game.spawnOrder to tableRowCount(game.Table 1).
I also would save the position of the spawned actor immediately so that a touch is released is not required (in case the player clicks to spawn a new gift and then changes scenes without repositioning it).
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang Thanks!!!! Working on it. You are right, if the player switches before he moves the spawned gift it goes away.
@tatiang The other thing I am having a problem is that when the player moves the spawned gifts around they do not delete from the previous position. I have tried to delete row when touch is pressed and then save position when touch is released. I guess I am not just getting the order correct.
@tatiang When i set up the loop over table in the responder, it also spawns the spawned gift in the very left bottom corner once the player goes to that scene. I cannot get the spawner actor to save the spawned gift right away. I have tried various ways.
I noticed that too when I tried to make a demo. It might be that you're spawning before/at the same time that the table data is loading. Try putting the Loop over Table behavior in an After 0.1 seconds Timer. Adjust that duration and see if it makes a difference.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang That didn't work. I assume now maybe it has something to do with the row one in the table. Since row one is already there with 0 values which make x and y 0(zero). I don't know how to fix that. I don't believe there is any way to remove row one at the start
@tatiang I have the spawned gifts saving. But when they are moved when coming back to the scene, they are in there new moved position and also their old position. If the players moves more than one in a scene, only the last one he moves gets saved to the new position and old position. The others that he moved stay in the old positions. Any thoughts.