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开发者_如何学JAVA, 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.
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.
- (CGFloat) rotation: **ERROR IS IN THIS LINE**
solution- Either pass parameters or remove colon (:)
Take out the colon and try like this
- (CGFloat) rotation
{ **THIS IS WHERE THE LINE ERROR OCCURS**
return rotation * 180.0/3.141592;
}
精彩评论