0

我希望能够做到这一点:

vec2 pos(1,5);
myActor.position = [Coord positionFrom: pos ];

使用我的结构:

typedef float32 float;
struct vec2 {
    vec2(float32 xx, float32 yy) {
        x = xx;
        y = yy;
    }
    float32 x, y;
};

坐标.h

@interface Coord : NSObject {
}
+(CGPoint) positionFrom: (vec2) pos;
+(CGPoint) positionFromAngle: (float32) angle;

坐标.mm

#import "Coord.h"
@implementation Coord
+(CGPoint) positionFrom:(vec2) pos {
    return CGPointMake( pos.x * 32, pos.y * 32);
}
+(CGPoint) positionFromAngle:(float32) angle {
    return CGPointMake( cos(angle) * 32, cos(angle) * 32);
}
@end

但是我得到了这些错误(在 Coord.h 中的 positionFrom 行):

Expected ')' before 'vec2'
Expected ')' before 'float32'
4

1 回答 1

0

这应该是:

+(CGPoint) positionFrom: (struct vec2) pos;

否则你没有导入定义vec2.

]您的return语句中还有一个尾随positionFrom:

顺便说一句,就风格而言,这种事情通常是用函数而不是类方法来完成的。像这样的东西:

CGPoint CGPointFromVec2( struct vec2 pos );

这使它平行于CGPointFromString().

于 2011-04-12T04:01:24.007 回答