Hi for starters let me say thank you for helping me out on this problem. I'm currently trying to learn Objective-C. I first started learning Java in AP Computer Science (taught at my High School) games... however, I've been trying to expand from Java into Objective-C. Mostly so I can mess around making iPhone apps. I've read quite a few guides but I keep getting stuck and overwhelmed so I just stop what I'm doing and head back to java.. However, this time I'm determined to get past this little problem! All responses are appreciated! So here is my VectorObject class that I will be using in my Sprite 2-D game Test Project. However, I'm having trouble with just general Objective-C syntax. I've tried several different things but can't seem to make it work, I just get errors.
TLDR: Here are my classes, I'm trying to make a VectorObject with the desired instance variables but I don't know how to properly add the parameter to the instance variable.
#import <Foundation/Foundation.h>
@interface VectorObject : NSObject
@property(nonatomic) BOOL alive;
@property(nonatomic) NSDecimal *x;
@property(nonatomic) NSDecimal *y;
@property(nonatomic) NSDecimal *velX;
@property(nonatomic) NSDecimal *velY;
@property(nonatomic) NSDecimal *maxVelX;
@property(nonatomic) NSDecimal *maxVelY;
@property(nonatomic) NSDecimal *moveAngle;
@property(nonatomic) NSNumber *faceAngle;
- (void)incX:(NSDecimal *) x;
- (void)incY:(NSDecimal *) y;
- (void)incVelY:(NSDecimal *) velY;
- (void)incVelX:(NSDecimal *) velX;
- (void)incFaceAngle:(NSDecimal *) faceAngle;
- (void)incMoveAngle:(NSDecimal *) moveAngle;
+ (NSDecimal)calcAngleMoveX:(NSDecimal *) ang;
+ (NSDecimal)calcAngleMoveY:(NSDecimal *) ang;
@end
And now for my implementation class.
#import "VectorObject.h"
@implementation VectorObject
@synthesize alive;
@synthesize x, y;
@synthesize velX, velY;
@synthesize maxVelX, maxVelY;
@synthesize moveAngle, faceAngle;
-(void)incY:(NSDecimal *)y
{
}
-(void)incX:(NSDecimal *)x
{
}
-(void)incVelY:(NSDecimal *)velY
{
}
-(void)incVelX:(NSDecimal *)velX
{
}
-(void)incFaceAngle:(NSDecimal *)faceAngle
{
}
-(void)incMoveAngle:(NSDecimal *)moveAngle
{
}
+(NSDecimal) calcAngleMoveX:(NSDecimal *)ang
{
}
+(NSDecimal) calcAngleMoveY:(NSDecimal *)ang
{
}
@end
So I know in Java I could simply define the incX(double x) like so
public void incX(double x)
{
this.x += x;
}
But I'm not sure how I would do this in Objective-C?
-(void)incX:(NSDecimal *)x
{
self.x += [NSDecimal *] x;
}
Edit: All syntax tips, general implementation, etc are appreciated and will be put to use!