1
\$\begingroup\$

I have an arrow image. I want to stretch this image between two given points. I'm retrieving the points from touch locations, so they aren't fixed. When the user touches the iPad, the arrow image should appear and be shown until the touch ends. So if the user touches point A and is moving his finger to point B, the arrow image will be stretched from point A to point B and so on.

How can I achieve that?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

First you need to compute the distance between points A and B, then you have stretch the arrow to this value. After that compute the angle between A and B, and rotate arrow with this.

The last operation is positioning the arrow. If origin of the picture is in the center, you must place it at the (A+B)/2 point.

\$\endgroup\$
0
\$\begingroup\$

I'm writeing this code in c++ since I'm working with cocos2d-x but you just have to translate this code to Obj-c:

ccPoint a,b;

image->setposition(ccp((a.x + b.x) / 2, (a.y + b.y)/2));
image->setrotation(atan2(a.y-b.y,a.x-b.x));

float dist = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
dist = dist / image->boundingbox().size.width;

image->setscale(dist);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .