drawing cocos2d v3 no longer has ccDraw* functions, how do I draw without making nodes?

夙愿已清 提交于 2019-12-18 09:35:15

问题


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.


回答1:


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]];

}


来源:https://stackoverflow.com/questions/28523010/drawing-cocos2d-v3-no-longer-has-ccdraw-functions-how-do-i-draw-without-making

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!