I am porting a project called sneakyness / SneakyInput hosted on github at https://github.com/sneakyness/SneakyInput. It's in objective-c for cocos2d-iphone . I want to port that to c++ for use in cocos2d-x.
In SneakyJoystick.h
The properties like
@property (nonatomic, readonly) CGPoint stickPosition;
where
CGPoint stickPosition
is a variable which is already defined. I have defined this variable normally as CCPoint stickPosition;
But I am very confused about the
@property (nonatomic, readonly) CGPoint stickPosition;
whether I should write it in c++ code or leave it.
Asked
Active
Viewed 233 times
2

srikanth chitturi
- 116
- 1
- 6
1 Answers
1
If you have code in C++ you can leave it as it is(C++) and interact with it with Objective-C without problems.
If instead your intentions are to rewrite everything to Objective-C then the objective C property should be put in place of a property in C++ :
Property in C++
private:
int x;
public:
int getX()
{
return x;
}
void setX(int value)
{
x = value;
}
Property in Objective-C
@property(nonatomic) int x;
@synthesize x;
Keep in mind that the property declaration in Objective-C is splitted into two files : the @property
goes into the header file(.h) while the @synthesize
goes into the implementation file(.m).
To understand better how @property
and @synthesize
works take a look at the apple declared properties documentation and/or at this other question .