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

Get help using Construct 2

Post » Tue Apr 01, 2014 10:31 pm

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 :D
You do not have the required permissions to view the files attached to this post.
B
5
Posts: 18
Reputation: 263

Post » Tue Apr 01, 2014 11:27 pm

@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
You do not have the required permissions to view the files attached to this post.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Wed Apr 02, 2014 5:34 pm

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^^)
B
5
Posts: 18
Reputation: 263

Post » Wed Apr 02, 2014 6:27 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Apr 02, 2014 6:45 pm

@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.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

Post » Wed Apr 02, 2014 7:19 pm

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!
B
5
Posts: 18
Reputation: 263


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests