3

所以我想在 cocos2d 上用图元创建一个圆形,然后将它用作精灵,请问我该怎么做?我知道我必须使用这样的东西:

glLineWidth(16); glColor4ub(0, 255, 0, 255); drawCircle( ccp(s.width/2, s.height/2), 100, 0, 10, NO); 但我很难理解它是如何工作的以及如何将它用作精灵

4

1 回答 1

4

你真的需要 CCSprite 实例吗?你可以创建一个 CCNode 的子类,然后在它的

- (void) draw

方法把你的代码放在那里。你的圈子将有它的中心位置 (0.f, 0.f)

@implementation MyScene

- (void) onEnter
{
    [super onEnter];
    CCNode* myNode = [MyNodeSubclass node];
    [node setPosition: someRandomPosition ];
    [self addChild: node];
}

@end

@implementation MyNodeSubclass

- (void) draw
{
    glColor4f(255, 255, 255, 255);
    CCPoint center = ccp(0.f, 0.f);
    CGFloat radius = 10.f;
    CGFloat angle = 0.f;
    NSInteger segments = 10;
    BOOL drawLineToCenter = YES;

    ccDrawCircle(center, radius, angle, segments, drawLineToCenter);    
}

@end

在这里写了这段代码,没有从 xcode 复制,但它应该可以按您的意愿工作。ccDrawCircle 是一个 cocos2d 函数,在 CCDrawingPrimitives.h 中声明

于 2012-04-13T13:03:10.063 回答