绘图cocos2d v3不再有ccDraw *函数,如何绘制而不制作节点? [英] drawing cocos2d v3 no longer has ccDraw* functions, how do I draw without making nodes?
问题描述
我按照 http://www.cocos2d-swift.org/get-started上的说明操作
,并通过Sprite Builder制作了一个新项目。
and made a new Project through Sprite Builder.
搜索ccDraw不显示任何东西。我在一个论坛上发现了这个例子,并实现了,但它看起来不正确。我不想要一个drawNode来资源税。我想要低级GL绘图线ccDrawLine如何工作。当我做一个这样的drawNode时,它不会重置旧的绘图 - 所以我画的所有行保留在屏幕上。
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.
如何绘制v2.x? (ccDrawLine,ccDrawCircle,ccDrawPoly)
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
a href =http://www.cocos2d-swift.org/docs/api/Classes/CCDrawNode.html =nofollow> http://www.cocos2d-swift.org/docs/api/Classes/ CCDrawNode.html 建议使用CCDrawNode效率不高。
http://www.cocos2d-swift.org/docs/api/Classes/CCDrawNode.html suggests using a CCDrawNode is not efficient.
推荐答案
只需稍微修改脉冲,如下图所示, draw
覆盖。
simply modify pulse slightly as follows, and get rid of the draw
override.
- (void)pulse {
x+= 1;
y+= 3;
if (x > 500) {
x = 0;
} else if (y > 500) {
y = 0;
}
// update the line segment
[_line01 clear];
[_line01 drawSegmentFrom:ccp(50, 50) to:ccp(x, y) radius:2 color:[CCColor colorWithRed:128 green:25/255 blue:3]];
}
这篇关于绘图cocos2d v3不再有ccDraw *函数,如何绘制而不制作节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!