“{”之前的预期标识符令牌 +因之前的错误而感到困惑,摆脱困境

发布于 2024-11-15 15:30:38 字数 1327 浏览 4 评论 0原文

我正在学习 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无可置疑 2024-11-22 15:30:38

从该行中删除 ':'

- (CGFloat) rotation:

':' 表示您正在向该函数传递一些参数。

重要:您似乎正在为方法和变量使用“旋转”名称。请改变这一点。

Remove ':' from that line

- (CGFloat) rotation:

':' 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.

萧瑟寒风 2024-11-22 15:30:38
- (CGFloat) rotation: **ERROR IS IN THIS LINE**

解决方案- 要么传递参数,要么删除冒号 (:)

- (CGFloat) rotation: **ERROR IS IN THIS LINE**

solution- Either pass parameters or remove colon (:)

鹿! 2024-11-22 15:30:38

取出结肠并尝试这样

- (CGFloat) rotation
{                                     **THIS IS WHERE THE LINE ERROR OCCURS**
return rotation * 180.0/3.141592;
}

Take out the colon and try like this

- (CGFloat) rotation
{                                     **THIS IS WHERE THE LINE ERROR OCCURS**
return rotation * 180.0/3.141592;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文