Dragging actor into position on Tower Defense

HappyKat78HappyKat78 Member, BASIC Posts: 173
Hi Guys,

Looking for some expert advice! I'm trying to set it up so I touch an icon (actor) which then spawns another actor on top of it, let's say a gun which can then be moved into position on the screen. I've setup the icon to spawn the gun when clicked and for the gun I have a rule that has a self attribute "FirstSelected" which is boolean and default to True. I then have it that if FirstSelected is true and touch is pressed then set the gun to the mouse coordinates. When touch is released then turn FirstSelected to false (so it drops the gun into position).

However, this works perfectly every time but the first time. The first time I touch the icon the gun spawns over the icon but doesn't move with the mouse/my finger. Any idea why this is and how I get it to work the first time as well?

Many thanks in advance for any help or advise!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If what's happening is that you click on the gun icon and a gun spawns but doesn't move anywhere and then you click on the gun icon again and the gun now moves with the mouse position, it's because the initial Touch is Pressed is true for the gun icon (you clicked on it) but not for the gun actor that was spawned (it didn't exist when you clicked). Once you release the click and click again on the gun icon, you're actually moving the gun that was spawned earlier and there should be another gun sitting on top of the icon unable to move.

    My recommendation would be to allow the player to click the gun icon and then release the mouse before clicking again to move the gun actor. You'd need a boolean on the gun icon actor so that it only spawns a new gun when the existing gun has been placed in position (after being moved away from the icon).

    If you still can't get it to work, post a screenshot of your rules and we'll see where we can go from there.

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    This works pretty well provided your gun actor is at least as big as the icon actor. Click the gray "gun icon," move the mouse to position the red "gun" and then click to place the red "gun."

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

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    Thanks for your comments. Yeah I can make this work, to confirm this is clicking to spawn the gun, moving it into place (with the mouse button up) and then clicking to lock it into place. However, how does this work with touchscreen? I'm designing this for mobile/tablet hence I was looking to use a drag functionality so it locks the gun into place once I have released it from touch (a la Field Runners)

    I think your original comment is right though, it's not recognizing the first touch as it didn't exist at the time. Do you have a way to get around that by any chance?

    Cheers!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Okay, then I would set it up so that the gun icon spawns a gun when Touch is Released and then the gun moves when Touch is Pressed and sets itself in place when Touch is Released, like in the attached demo.

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

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    Thanks for the speedy response! So in this example you have to touch once to load the gun then you release and drag it into place. Do you think it's not possible to touch and drag it all in one swift movement like they do in field Runners?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I was going to say I don't think so, but then I had an idea for how it might work. Have the gun icon spawn a gun but have the gun's self.color.alpha set to 0 so it's hidden. Then when you touch the gun icon, have the gun change self.color.alpha to 1 and allow it to move with the tap/drag. The key is to have the gun icon spawn a copy of itself and destroy itself or else have the gun icon spawn another hidden gun to replace the one that gets moved.

    If I can get a demo working, I'll post it here.

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

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    That's a good idea! I'll try it, thanks!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    You can see it in action here, with pigs :P

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Since you probably will have rules for your gun that fire bullets, you'll need to only enable those rules when the gun has been placed. But hopefully you can figure that out from the booleans I've included in the demo.

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

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    Thanks so much! I actually got the same result a bit differently. I didn't spawn and destroy the icon as I didn't see the need, instead I just had it spawn the gun with alpha at 0 at the beginning of the level and then every time I click on the icon I make the existing gun alpha's 1 and then spawn a new gun with alpha at 0. This works well. Thanks again for all of your help!!!
  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    To your other point, I can probably just use Alpha = 1 or Alpha >0 as a rule to make the gun become active. Cheers!
Sign In or Register to comment.