Hello,
In my game prototype, once I touch the screen it adds a point, then I touch the screen again and it adds another point and then try to draw a line between these two points.
Note that the both the point (which I call "circle") and the line are sprites. So the line is being scaled according to the distance between the points.
The problem I'm facing is how to inclinate the line to connect it between the two points?
I'm trying the following:
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
CCSprite *newCircle = [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"circle"]];
newCircle.position = ccp(touchLocation.x, touchLocation.y);
newCircle.anchorPoint = ccp(0,0);
if(openCircle != nil) {
CCSprite *newLine = [CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"line"]];
newLine.position = openCircle.position;
newLine.anchorPoint = ccp(0,0);
float deltaX = newCircle.position.x - openCircle.position.x;
float deltaY = newCircle.position.y - openCircle.position.y;
float distance = ccpDistance(openCircle.position, newCircle.position);
NSLog(@"Angle: %f\n", CC_RADIANS_TO_DEGREES(ccpAngle(openCircle.position, newCircle.position)));
[newLine setScaleX:distance];
[newLine setRotation:CC_RADIANS_TO_DEGREES(ccpAngle(openCircle.position, newCircle.position))];
[self addChild:newLine];
openCircle = nil;
} else {
openCircle = newCircle;
}
[self addChild:newCircle];
}
I thought that:
[newLine setRotation:CC_RADIANS_TO_DEGREES(ccpAngle(openCircle.position, newCircle.position))]
would put the line sprite on the right inclination. But it just doesn't work at all.
Any tips / ideas?
Here is what I'm getting:

Thanks.
