Reputation: 3379
i try to return a CGPoint but i do something wrong:
Here is my method:
- (CGPoint)calculatePointOnCircleFrom:(CGPoint)pointA PointB:(CGPoint)pointB radius:(float)rd {
float sryy = pointA.y - pointB.y;
float srxx = pointA.x - pointB.x;
float sry = pointA.y + sryy;
float srx = pointA.x + srxx;
float kpx = pointA.x + cos(atan2(pointA.y - sry, pointA.x - srx)) * rd;
float kpy = pointA.y + sin(atan2(pointA.y - sry, pointA.x - srx)) * rd;
return CGPointMake(kpx, kpy);
}
The code in the method works fine but i do something wrong with the initialization.
Here i call the method:
point1.position = [self calculatePointOnCircleFrom:Player.position PointB:touchPos radius:64];
and get fooling error: "incompatible type for argument 1 of 'setPosition:'"
Upvotes: 0
Views: 2060
Reputation: 3379
I solved the problem on a not perfect way but it works.
I return know a NSValue:
- (NSValue *)calculatePointOnCircleFrom:(CGPoint)pointA PointB:(CGPoint)pointB radius:(float)rd {
float sryy = pointA.y - pointB.y;
float srxx = pointA.x - pointB.x;
float sry = pointA.y + sryy;
float srx = pointA.x + srxx;
float kpx = pointA.x + cos(atan2(pointA.y - sry, pointA.x - srx)) * rd;
float kpy = pointA.y + sin(atan2(pointA.y - sry, pointA.x - srx)) * rd;
return [NSValue valueWithCGPoint:CGPointMake(kpx, kpy)];
}
and call method like so:
NSValue *pos = [self calculatePointOnCircleFrom:Player.position PointB:touchPos radius:64];
CGPoint cgpos = [pos CGPointValue];
point1.position = cgpos;
Thanks for every ones help :D
Upvotes: 0
Reputation: 237110
There's probably also a warning that it can't find the method declaration. It sounds like the compiler doesn't know what type the method returns and is defaulting to id.
Upvotes: 0
Reputation: 6240
If you look closely you'll see that the message is about an incompatible type for argument 1 of a method called setPosition
, not the calculatePointOnCircleFrom
method. The setPosition
is the setter for the position
property.
So the problem is with the point1.position =
part of the line, not the call to the calculatePointOnCircleFrom
method. I suspect the position
property of the point1
variable is not of type CGPoint since that's what the calculatePointOnCircleFrom
method is returning.
Alternatively, you may not be calling the method you think you're calling.
Upvotes: 2
Reputation: 27900
That error message is telling you that the type returned by [self calculatePointOnCircleFrom:Player.position PointB:touchPos radius:64]
does not match the type of point1.position
. Is position
a CGPoint?
Upvotes: 0