I want to test how big the bounding box on my sprites but it is not working no rectangles are being drawn
SETUP OF THE SPRITE IMAGE BEING SHOWN
ball = CCSprite::createWithSpriteFrameName(“ball.png”);
ball~~>setPosition);
this~~>addChild(ball);
drawBoundingBox(ball);
FUNCTION TO DRAW THE OUTLINE OF THE BOUNDING BOX
void HelloWorld::drawBoundingBox(CCSprite* sprite){
CCRect box = sprite->boundingBox();
ccDrawRect(ccp(box.origin.x, box.origin.y),ccp(box.origin.x+box.size.width, box.origin.y+box.size.height));
}
My first question is what default color rectangle should that draw? and on what zOrder? because i have my sprites on top of a background picture.
If i just call ccDrawRect should it not just draw?
Hi, you should override the method *void draw()* and then call your drawBoundingBox(ball) method form draw method.
You should always call your rendering related stuff from draw() method. The default color will be white. Hope it will help you
Do i have to override? I dont see how that would make a difference? can’t we draw shapes just by using the ccDrawRect or ccDrawCircle ?
Would overriding be the easiest way to draw the boundbox outline? I just need it for debug purposes
I did more research and found CC_SPRITE_DEBUG_DRAW and CC_SPRITEBATCHNODE_DEBUG_DRAW in the ccConfig.h inside libs/cocos2dx/include folder just set them to one and it draws the bounding box around all the sprites.
I would still like to learn about overriding draw() if anyone could explain it to me =)
1 Like