Created
August 20, 2015 15:01
-
-
Save brunoro/ec3904230f53dd6118fa to your computer and use it in GitHub Desktop.
Visualize Bézier curves in cocos2d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "cocos2d.h" | |
@interface BezierCurveNode : CCNode | |
@property (nonatomic) CGPoint origin; | |
@property (nonatomic) CGPoint cp1; | |
@property (nonatomic) CGPoint cp2; | |
@property (nonatomic) CGPoint destination; | |
@property (nonatomic) ccColor3B color; | |
- (id)initWithOrigin:(CGPoint)origin | |
controlPoint1:(CGPoint)cp1 | |
controlPoint2:(CGPoint)cp2 | |
destination:(CGPoint)destination | |
color:(ccColor3B)color; | |
- (id)initWithOrigin:(CGPoint)origin config:(ccBezierConfig)config; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "BezierCurveNode.h" | |
#import "cocos2d.h" | |
@implementation BezierCurveNode | |
- (id)initWithOrigin:(CGPoint)origin | |
controlPoint1:(CGPoint)cp1 | |
controlPoint2:(CGPoint)cp2 | |
destination:(CGPoint)destination | |
color:(ccColor3B)color | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
_origin = origin; | |
_cp1 = cp1; | |
_cp2 = cp2; | |
_destination = destination; | |
_color = color; | |
} | |
return self; | |
} | |
- (id)initWithOrigin:(CGPoint)origin config:(ccBezierConfig)config | |
{ | |
return [self initWithOrigin:origin | |
controlPoint1:config.controlPoint_1 | |
controlPoint2:config.controlPoint_2 | |
destination:config.endPosition | |
color:ccc3(120, 0, 120)]; | |
} | |
- (void)visit | |
{ | |
[super visit]; | |
ccPointSize(10); | |
ccDrawColor4F(_color.r / 255.0, _color.g / 255.0, _color.b / 255.0, 1.0f); | |
ccDrawCircle(self.cp1, 5, 0, 20, NO); | |
ccDrawCircle(self.cp2, 8, 0, 20, NO); | |
ccDrawCubicBezier(self.origin, self.cp1, self.cp2, self.destination, 20); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment