Closed PaulSolt closed 10 years ago
The two new methods are
userInteractionEnabledand
isRunningInActiveSceneon CCNode.
Should those properties be overridden and then called from the forwardInvocation: and methodSignatureForSelector: methods?
I think you could implement it by just keeping old isTouchEnabled inside all code, just modify code for forwardInvocation and methodSignature, so if selector is not found then you first check if the instance supports the 3.0 methods. If so then you use them. Does that make sense?
Something along the lines of:
if (![self respondsToSelector:aSelector]) {
if (aSelector == @selector(isTouchEnabled)) {
if([self respondsToSelector:@selector(userInteractionEnabled)]) {
return [self methodSignatureForSelector:@selector(userInteractionEnabled)];
}
return [self methodSignatureForSelector:@selector(sf_isTouchEnabled)];
...
Ok, it's working for Cocos2d 1.x, 2.x, and 3.x.
I didn't change the forwardInvocation and methodSignature. Instead I added calls to check if the current instance responds to a selector and changed the methods:
- (BOOL)sf_isPointInArea:(CGPoint)pt
and
- (BOOL)isPointTouchableInArea:(CGPoint)pt
to call the appropriate method (isRunning, isRunningInActiveScene, and isUserInteractionEnabled).
I have it working for Cocos2d 3.0 sample project, but I'm not exactly how to add legacy support. The legacy projects do not build with these changes.
How do you recommend handling the API differences from 2.x to 3.x?
CCArray doesn't exist in 3.0 I think this can be safely used as a normal for loop on 1.x and 2.x
userInteractionEnabled has been added to CCNode
I'm not sure the best approach for adding backwards compatibility with the API change from 2.x to 3.x. I get build errors if I try to do this: