How can I spawn actor on touch and drag and drop?

swongswong Member Posts: 15

Hi there,
I'm currently working on a project and I'm at the hardest part.

I have a list of items, and I want to spawn an actor on touch and have it drag and drop.
Similar to this example unfortunately, the link in the description isn't available.
I've seen some other threads like http://forums.gamesalad.com/discussion/8876/spawn-actor-at-touch but it doesn't really make sense to me and I don't think it's exactly what I'm looking for.

Any help would be much appreciated!
Thanks in advance.
Sam

Comments

  • MoikMoik Member, PRO Posts: 257
    edited May 2014

    From what I understand, the actors you want to spawn need to be already existing in the background/off-screen/in your list.

    Then, on the area you want the person to touch and get their object, you add a Touch command with a Spawn Actor Behavior. I don't know if this spawns copies on subsequent touches or not. You may need to make it loop through a set of pre-made sequence of actors.

    The actors themselves should have a Touch command with two Constrain Attribute behaviors. One to constrain the object's X position to the Mouse X position, and then another to constrain the object's Y position to the Mouse Y position.

  • MoikMoik Member, PRO Posts: 257

    Turns out subsequent touches do copy. The forum doesn't seem to want to let me attach a file.

    You'll also need to have the Spawn Actor behavior spawn at MouseX and MouseY relative to the scene.
    And the key trick is to use "When Touch is Inside" on the Spawn Actor to have it automatically drag.

  • swongswong Member Posts: 15

    Hey @Moik‌ , thanks for the help!

    I actually already had something similar; but after the edit, i have for the area i want pressed:

    • touch is pressed
    • spawn actor - from position mouse.position.x, mouse.position.y relative to scene

    Then for the actor i want spawned (which is already on scene, but off canvas) i have:

    • touch is inside
    • constrain self.position.x to mouse.position x
    • constrain self.position.y to mouse.position.y

    The issue is that the newly spawned actor doesn't drop when i release mouse click and just follows the cursor. And i'm not sure if subsequent touches copy, but i think it does.

    In the video, i'm sure they have a boolean which returns true on click and false on release. Not sure what they does exactly or what i could do with it.

    Any advice?

  • MoikMoik Member, PRO Posts: 257

    Dropping is a physics thing I haven't looked into much. My gut says it's an "Accelerate Toward" behavior that's ended by collision.

    I would think the on-release Boolean is to stop the player from picking the object up again and moving it again. Probably the Spawn Actor actor has a rule that set's the Boolean back to True so the spawned one can be moved.

  • swongswong Member Posts: 15

    Hmm thanks Moik.

    But when you say dropping, do you mean when the spawned actor is released and falls by gravity? Because what i meant was that if i do: on touch inside to the actor i wanted spawned, it doesn't drop after i've dragged it where i want and therefore drags but doesn't drop.

    I've tried pressed, which creates the spawn actor but have to click again to drag and then it drops.

    I can't seem to find anything related to touch inside and dropping.

    Do you think I'd need an attribute to make it work?

  • MoikMoik Member, PRO Posts: 257

    So, by Drop, do you mean 'it falls toward the bottom of the screen" or more like "it becomes inserted into the thing it's hovering over or applies a selection"?

  • swongswong Member Posts: 15

    Never mind Moik, I found a tower defence template which is quite similar to what I was looking for. But thanks for your help!

    I've got a new problem now..

    forums.gamesalad.com/discussion/68494/why-are-cloned-spawn-actors-destroyed-when-overlapped-and-clicked?new=1

Sign In or Register to comment.