Search code examples
objective-ccocos2d-iphone

CCDrawNode width and height are always {0, 0}


I'm trying to get the boundinBox.size.with and is always 0. I'm using CCDrawNode. I initialize it like this:

-(void)initNode
{
    CGPoint vertices[4] = {
        ccp(0.f, 0.f),
        ccp(0.f, 15),
        ccp(50, 15),
        ccp(50, 0.f)
    };

    [self.lineOneRed drawPolyWithVerts:vertices
                                 count:4
                             fillColor:[CCColor redColor]
                           borderWidth:1.f
                           borderColor:[CCColor redColor]];
    [self.lineOneRed setPosition:ccp(x,y)];
    [self addChild:self.lineOneRed z:10];
}

Does anybody know why?


Solution

  • Most likely at no point did you set the content size of that node, and bounding box uses that in part of its calculations. Try setting the content size yourself and see if that fixes it. I can't confirm at the moment, but I don't believe those draw methods in that particular class sets the content size.