How do I hold a sprite with the mouse moves?

0 favourites
  • 6 posts
From the Asset Store
Create your game with this complete pack of images and animations!
  • How do I make a simulation of how to pick up an object? for example: a chess game!

    In short I need:

    1 - first click - grab and hold the piece

    2 - the piece follow the same place the cursor across the board like a ghost

    3 - second click - drop the piece

    I guess that is how to became the cursor on the piece until release it on right place of the play.

    Thanks for the support!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Add the drag & drop behavior.

    EDIT: oh, but you don't want to drag it.. you could toggle a boolean instance variable (state) which tells it whether or not it's dragging.

    like, on click sprite, toggle boolean variable.

    if variable true set sprite position to mouse.x, mouse.y

  • oh buddy I forgot to say the point of my problem

    sorry!!!

    to be clear I tried to move the sprite together to cursor after RELEASE the mouse button.

    in other words

    move mouse = move sprite

    without hold any button

  • I think what I told you should work. unless I'm not understanding you. (I think you mean drop, not large)

    If you're not dragging it, don't use drag & drop.

    I'll try to be more clear. and maybe I'm just misunderstanding.

    Give the piece an instance boolean variable. call it "hold", set it false.

    1.

    On piece clicked, toggle "hold"

    2.

    If "hold" = true, set piece position to mouse.x, mouse.y.

    3.

    (no code necessary) next click will set "hold" to false and it will no longer stay with the mouse cursor.

    I'm not sure why you want to destroy and recreate the piece if you're just moving it?

    Hope that helps!

  • You can visit my Chess board made with Construct 2.

    Don't forget skip add.

    Check it out:

    Sorry, if you want the link, please private.

  • I think what I told you should work. unless I'm not understanding you. (I think you mean drop, not large)

    If you're not dragging it, don't use drag & drop.

    I'll try to be more clear. and maybe I'm just misunderstanding.

    Give the piece an instance boolean variable. call it "hold", set it false.

    1.

    On piece clicked, toggle "hold"

    2.

    If "hold" = true, set piece position to mouse.x, mouse.y.

    3.

    (no code necessary) next click will set "hold" to false and it will no longer stay with the mouse cursor.

    I'm not sure why you want to destroy and recreate the piece if you're just moving it?

    Hope that helps!

    I know that this thread is really old but thank you sooo much!!!!!!

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