Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer

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));

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;

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.