我在这里使用剪辑节点:http: //www.learn-cocos2d.com/2011/01/cocos2d-gem-clippingnode
ClippingNode.h
#import "cocos2d.h"
@interface ClippingNode : CCNode {
CGRect clippingRegionInNodeCoordinates;
CGRect clippingRegion;
}
@property (nonatomic) CGRect clippingRegion;
@end
ClippingNode.m
#import "ClippingNode.h"
@interface ClippingNode (PrivateMethods)
-(void) deviceOrientationChanged:(NSNotification*)notification;
@end
@implementation ClippingNode
-(CGRect) clippingRegion {
return clippingRegionInNodeCoordinates;
}
-(void) setClippingRegion:(CGRect)region {
// keep the original region coordinates in case the user wants them back unchanged
clippingRegionInNodeCoordinates = region;
self.position = clippingRegionInNodeCoordinates.origin;
self.contentSize = clippingRegionInNodeCoordinates.size;
// convert to retina coordinates if needed
region = CC_RECT_POINTS_TO_PIXELS(region);
// respect scaling
clippingRegion = CGRectMake(region.origin.x * scaleX_, region.origin.y * scaleY_,
region.size.width * scaleX_, region.size.height * scaleY_);
}
-(void) setScale:(float)newScale {
[super setScale:newScale];
// re-adjust the clipping region according to the current scale factor
[self setClippingRegion:clippingRegionInNodeCoordinates];
}
-(void) deviceOrientationChanged:(NSNotification*)notification {
// re-adjust the clipping region according to the current orientation
[self setClippingRegion:clippingRegionInNodeCoordinates];
}
-(void) visit {
glEnable(GL_SCISSOR_TEST);
CGPoint worldPosition = [self convertToWorldSpace:CGPointZero];
const CGFloat s = [[CCDirector sharedDirector] contentScaleFactor];
glScissor((clippingRegion.origin.x) + (worldPosition.x*s), (clippingRegion.origin.y) + (worldPosition.y*s),
(clippingRegion.size.width), (clippingRegion.size.height));
[super visit];
glDisable(GL_SCISSOR_TEST);
}
@end
但是,我需要剪辑一个旋转的 CCNode。关于如何完成这样的任务的任何想法?