我正在学习Objective-C上的游戏编程,并按照本书的说法输入代码。到目前为止,我已经能够清除所有的错误/错误,但这个错误让我感到安慰。
这是代码,我标记了编译器声明错误的位置:
#import "Sprite.h"
@implementation Sprite
@synthesize x, y, speed, angle, width, height, scale, frame, box, rotation, wrap,render;
@synthesize r, g, b, alpha, offScreen;
- (id) init
{
self = [super init];
if (self) {
wrap = NO;
x = y = 0.0;
width = height = 1.0;
scale = 1.0;
speed = 0.0;
angle = 0.0;
rotation = 0;
cosTheta = 1.0;
sinTheta = 0.0;
r = 1.0;
g = 1.0;
b = 1.0;
alpha = 1.0;
offScreen = NO;
box = CGRectMake(0, 0, 0, 0);
frame = 0;
render = YES;
}
return self;
}
- (void) draw: (CGContextRef) context
{
CGContextSaveGState(context);
// Position the sprite
CGAffineTransform t = CGAffineTransformIdentity;
t = CGAffineTransformTranslate(t,x,y);
t = CGAffineTransformRotate(t, rotation);
t = CGAffineTransformScale(t, scale, scale);
CGContextConcatCTM(context, t);
// Draw our body
[self drawBody: context];
CGContextRestoreGState(context);
}
- (void) setRotation: (CGFloat) degrees
{
rotation = degrees * 3.141592/180.0;
}
- (CGFloat) rotation:
{ **THIS IS WHERE THE LINE ERROR OCCURS**
return rotation * 180.0/3.141592;
}
任何帮助都是适用的。提前谢谢。
答案 0 :(得分:2)
从该行中删除':'
- (CGFloat) rotation:
':'表示您正在将一些参数传递给该函数。
重要:您似乎使用方法和变量的“轮换”名称。请改变它。
答案 1 :(得分:1)
- (CGFloat) rotation: **ERROR IS IN THIS LINE**
solution-传递参数或删除冒号(:)
答案 2 :(得分:0)
取出冒号并尝试这样
- (CGFloat) rotation
{ **THIS IS WHERE THE LINE ERROR OCCURS**
return rotation * 180.0/3.141592;
}