0 Favourites

How do I use touch to move a sprite and change pivot point

  • Dear Fellows,

    currently i am working on a simple mechanism to move a sprite with touch.

    i just want to move the object it on the y-axe, its okay in that way.

    now i have a problem:

    When i moved the object and touch it at the top (instead of the center), the object jumps "up", the touch seems to be snap the item right into the center of the pivot.

    What i want to perform is a "smooth" touch => i touch the object at any point, and then i can move it "normally".

    instead of jumping, the touch movement should be done right where i touched the object, and not jumping into the center of the object.

    i attached a small drawing in order to explain what goes wrong.

    with the simple "Touch => Is Touching Object => Set position.Y to Touch.Y" or "to Touch.AbsoluteY" it jumps like that. any idea or a link to a tutorial?

    what i want to do, is that i touch it at anypoint and move it from the current touch position +/- Y.

    aaand sorry it's late night and i am from germany, my english isn't just the best i've written. but i am tired

  • wolfomat

    Do you want something like this?

    The blue box centers to touch. The red box only centers the to the Y of the touch.

    You can change the speed by adjusting the 0.05 value

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • thanks for your reply shirokuma, it looks really smooth and nice as an alternative to what i am looking for.

    what i am looking for is, that i don't want the object to move to center of the touch so when i touch the object on the bottom left and i move my finger/mouse, then the object should be moved from this touching point and no translation to center on touch - you get the idea? (i still think my explainations are not that good, sorry^^)

  • If the build in drag and drop behaviour doesn't suit your needs, best way would be to use offset..

    If you want to program it yourself, something like this should do it:

    Give the object an offsetx and offsety instance variable.

    on object touched

    • set object.offsetx to touch.x-object.x
    • set object.offsety to touch.y-object.y

    Is touching object

    • object set position to x: touch.x-object.offsetx, y: touch.y-object.offsety

    But I gues using the drag and drop - behaviour would work just as well.

  • wolfomat

    Ah... Now I understand.

    Just add the drag and drop behavior to the sprite, and in the properties panel you can set the behavior to only work in the vertical axis.

  • thanks LittleStain and shirokuma - the drag and drop behaviours is exactly that what i was looking for!!!

    It works just as intended right now - perfect!

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