“{”之前的预期标识符令牌 +因之前的错误而感到困惑,摆脱困境
我正在学习 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;
}
需要任何帮助。提前致谢。
I am learning game programming on Objective-C and typing code as I follow along this book. I've been able to clean up all mistakes/errors thus far, but this one just escapes me.
Here's the code, I marked where the compiler states the error:
#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;
}
any help is appreicated. thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从该行中删除 ':'
':' 表示您正在向该函数传递一些参数。
重要:您似乎正在为方法和变量使用“旋转”名称。请改变这一点。
Remove ':' from that line
':' indicates that you are passing some parameters to that function.
IMPORTANT: It seems you are using "rotation" name for method and variable. Please change that.
解决方案- 要么传递参数,要么删除冒号 (:)
solution- Either pass parameters or remove colon (:)
取出结肠并尝试这样
Take out the colon and try like this