Question: Spawning actors from HUD icon, different layers

Hello,

I'm new to GameSalad and after a lot of searching on Google and the forums, I've yet to find an answer to this question. So I'll try to ask it here!

I'm working with a game idea where I have a non-scrollable HUD that has a button on it. What I want to have happen is when the button is touched, an actor spawns at the mouse/touch location and can be dragged and dropped (mouse/touch release) into a playable area. This should be able to happen several times to create multiple instances of the actor.

I've gotten most of the way there myself, but the issue I am having is that when I spawn a new actor, I think it is stuck in the HUD layer (non-scrollable), so when I scroll the background screen, the actor is mistakenly dragged along in it. I want the new actor to spawn into a scrollable layer. I've also tried doing it differently, where the actor already exists off-screen in the correct layer and is moved to the mouse location when the button is pressed, but then I do not know how to make multiple instances of the actor to do this.

Any help would be greatly appreciated! Thanks!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You've discovered that you can only spawn actors in their own layer. You'll probably need to trigger a spawner actor on a scrollable layer to spawn. Actors can communicate with each other via game attributes (often boolean or integer). So for example, your HUD button could change game.spawn to true and your spawner actor could spawn an actor when game.spawn is true and then change game.spawn back to false to be ready for the next time the HUD button is pressed.

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

  • AirshipScientistAirshipScientist Member Posts: 21
    tatiang,

    Thanks a lot for the suggestion. This might be very simple, but I have a follow up question. Once I have the spawner spawn an actor in the correct layer, I'd like the actor to be constrained to the mouse so it can be placed and released. This seems straightforward if I only wanted to make one new actor, but I want to make multiple. If I constrain the actor prototype to the mouse position when I spawn it, any existing actors get stuck on the mouse position. I want to place each new actor individually. Hope that makes sense. Do you (or anyone else reading this!) have any recommendations? Thanks!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    In the spawned actor prototype, have an actor boolean called self.placed. Set it to false (unchecked). When the player places (touch is pressed?) the actor on the scene, change self.placed to true. Add a rule around your constrain behavior with the condition self.placed=false.

    That way, once an actor has been placed on the scene, it won't constrain to the mouse position.

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

  • AirshipScientistAirshipScientist Member Posts: 21
    Awesome, thanks for the help.
Sign In or Register to comment.