# How to create a line that is always connected to two Objects. (iPhone, Cocos2d)

I'm wanting to create a rope like animation effect. I don't need any kind of rope physics, all I need is a straight line connected to Object A and the other end connected to object B. Object A and B move relative to one another. So how do I make it so that the line is always attached to both Objects, even thought the distance between the objects decrease and increase?

The game is in 2D space.

• You say it only needs to be straight while also saying it needs to contract and expand. Which is it? – Attackfarm Jan 15 '15 at 10:39
• It only needs to be straight in the sense that it doesn't bend and is straight like an arrow. When is said contract and expand I meant it follows the harpoon as it goes up and down, but it isn't actually contracting and expanding, it just looks like it. Trying to make it simple: have you played the game goldminer? Thats what I need. A rope that acts like that rope, which is just a straight line that follows the claw object. – Sp3kk Jan 15 '15 at 15:57
• So what are you trying and where are you getting stuck? Because it sounds like literally all you need is a black line. – Attackfarm Jan 16 '15 at 23:42
• Yes, a black or preferably a brown line that is connected to object A and object B at all time. Even thought A and B move relative to one another in 2D space (Sideways & Up/Down). So I don't know how to keep the line connected to both A and B at all times, thats where I get stuck. – Sp3kk Jan 17 '15 at 10:49
• You know what, I'll rephrase my question for simplicity. – Sp3kk Jan 17 '15 at 11:15

Point start = objectA.position