How do I make drag and drop possible for very small sprites?

0 favourites
  • 8 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • Hello everyone,

    I've been trying to run my C2 game on a smartphone and everything works great, except for one thing: The drag and drop sprites are too small for my big-ass thumb to drag them around.

    Now I'm trying to find a way to make the drag possible though without adjusting the size of the collision polygon, because that would compromise the whole project. I've tried the following thing:

    • I've created an invisible sprite, made it bigger than the drag and drop object and then pinned it to it, but this leads to a whole bunch to other problems. When a drag starts for the invisible sprite, I first have to pick the corresponding opaque sprite bellow it by comparing an instance variable that I have set to both sprites, then I have to unpin it from the original opaque sprite, then pin the opaque sprite below to it, and reverse all those actions when the invisble sprite is dropped. The major problem is that picking does not seem to work the way it should, I've experienced a lot of troubles with the picking action so far. Adding to that, setting up an invisbile sprite would double the amount of sprites and make the FPS drop significantly.
    • Is there any way to set up the drag and drop behaviour so that a drag is being initiated when the touch (or click) does not happen in the collision polygon only, but in the collision polygon resized by some factor? Maybe there is a plugin? That would solve it all.
    • If you have any other ideas, please tell me.
  • put the invisible sprite in a container with the drag/drop object.

    The invisible sprite will do everything the object does (and vice versa), including picking.

    Yes, this means you have an invisible sprite for every single drag/drop object, but that shouldn't cause your FPS to drop significantly, if at all.

    EDIT: I'd still do it the way I said above, but another way, which is closer to what you asked for, would be like:

    on touch

    pick nearest drag/drop object to touch.x, touch.y

    check the distance between the touch and the drag/drop is not too much

    and then initiate the dragging that way.

  • I've had the same issue myself. You'll want to use the container method spacedoubt stated above. Using the second method causes trouble if you have a lot of sprites.

  • If you show the events that give a picking issue we may be able to expain what's going on.

    Otherwise here's my first idea:

    Just have your tiny sprites and give them the drag drop behavior. Then do one event to do this:

    On touch

    Pick Sprite closest to touch.x, touch.y

    --- Sprite: set position to touch.x, touch.y

    That would move the Sprite to where you touched, and I'm taking a guess that might let it start dragging. If not then scrap that idea, but if it works you could use a pick by comparison to pick only sprites within a radius.

    Your drag n drop and pin idea sounds like it should work, but I'd have to test it otherwise I can't predict what it would do.

    An alternate idea would be to not use the dragdrop behavior and do it with events.

    global number obj=-1

    On touch

    Pick Sprite by comparison distance(Sprite.x,Sprite.y,touch.x,touch.y)<64

    Pick Sprite closest to touch.x, touch.y

    --- set obj to Sprite.uid

    Is touching

    Pick Sprite by uid: obj

    --- Sprite: set position to touch.x, touch.y

    On touch released

    --- set obj to -1

    That should work. Now you can also save the xy offset when you touch and use that when setting the position to keep the relative offset.

  • Thanks for the advice! I'll do some tests and let you know whether it worked.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1. Tried the idea with the containers. Sadly, you can't put a sprite family and a sprite in a container. As the physics engine in my game interacts with the drag'n drop behaviour, I have to work with families. Besides that, I'd still have to pin and repin the objects in the container... or maybe I'm not getting your point about using a container?

    2. Tried the idea of picking nearest objects to touch position and set them to touch position. Works! Now there's only one minor problem left:

    How do I pick the nearest object to a point? Can't use min() in that case.

  • The "pick closest" object condition does that.

  • Ah, I see. I was searching under 'System', not under the object itself.

    Alright, Problem solved.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)