Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

2 Answers

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);
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.