IOS Drag and Release touch event

Posts: 2
Joined: 2014.08
Post: #1
Hello, I am a young programmer currently building a game and I have ran in to a problem in getting a particular touch movement gesture.

here is a imgur of my problem expressed visually of what I am trying to achieve.

based on that here is my code to combat the problem.

Another thing is that there is not that many resources out there to perform this type of movement and the resources out there mainly for drag and drop.

Hope this is enough detail, but if you I ask for more, I will provide more detail.

Thank you.

Another example of the touch gesture I am trying to achieve is from hearthstone drag attack but instead of an animation I am using a SKShapenode

here is the link of the example
Quote this message in a reply
⌘-R in Chief
Posts: 1,277
Joined: 2002.05
Post: #2
You didn't actually say what the problem was...

Reading the code I can guess that your problem is the line simply not drawing in the right spot, which is because your coordinates are all messed up.

In touchesBegan: you're making a CGPath with a line that goes from {0, 0} to the coordinates of the node's position. That's not what you want.

You want a line that visually goes from the node's position to the position of the touch. If you were to MoveToPoint(node.position), LineToPoint(location), then that shapeLine node would have to be as big as the parent node itself, and position at {0, 0} so the coordinate systems line up.

Better would be MoveToPoint(0, 0) and LineToPoint(location.x - node.x, location.y - node.y), and then position that shapeLine at the node's starting location. Now that shapeLine is as small as possible and positioned correctly.
Quote this message in a reply
Posts: 2
Joined: 2014.08
Post: #3
Sorry about that, and thanks for the reply.

The problem that I was failing to address was the I am trying to achieve that touch gesture of touching a sprite and dragging (making a SKShapeNode appear to aid you in moving the node to your desired location when touch ends).

Another Thing that can help I was reverse engineering this game I found from github to get that drag release effect.

This is the code I used reverse engineering and changed it to the one you see at my first post (note: there is 2 images in the imgur),mTcqKFd#0
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  When to run event loop... SethWillits 3 5,916 Aug 11, 2002 07:48 AM
Last Post: ededed