I followed the instructions on http://www.cocos2d-swift.org/get-started
and made a new Project through Sprite Builder.
searching for ccDraw doesn't show anything. I found this example on a forum, and implemented, but it doesn't look right. I don't want a drawNode that taxes resources. I want low level GL drawing line how ccDrawLine used to work. When I do a drawNode like this -- it doesn't reset the old drawing -- so all lines I draw stay on the screen.
How do I draw like in v2.x? (ccDrawLine, ccDrawCircle, ccDrawPoly)
#import "MainScene.h"
@implementation MainScene
- (id)init {
self = [super init];
_line01 = [CCDrawNode node];
[self addChild:_line01];
[self schedule:@selector(pulse) interval:0.016];
return self;
}
- (void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform {
[_line01 drawSegmentFrom:ccp(50, 50) to:ccp(x, y) radius:2 color:[CCColor colorWithRed:128 green:25/255 blue:3]];
}
- (void)pulse {
x+= 1;
y+= 3;
if (x > 500) {
x = 0;
} else if (y > 500) {
y = 0;
}
}
@end
http://www.cocos2d-swift.org/docs/api/Classes/CCDrawNode.html suggests using a CCDrawNode is not efficient.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…