1
votes

I am trying to show bounding rectangles around my sprites to refine the collision detection and handling.

I have used following code to display circle or polygon

        glColor4ub(255, 255, 0, 255);
    glLineWidth(2);
    CGPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) };
    ccDrawPoly( vertices2, 3, YES);

    ccDrawCircle(ccp(0,0), 50, 360, 5, NO); 

as mentioned in drawPrimitivesTest.m file in cocos2d.

i removed all background sprites also. but it is not showing me any circle or polygon.

can anybody has faced same problem? how to solve this problem?

Thanks in advance.

1

1 Answers

1
votes

You should not put that code outside of the draw method

TIP: Every CocosNode has a "draw" method. In the "draw" method you put all the code that actually draws your node. And Test1 is a subclass of TestDemo, which is a subclass of Layer, which is a subclass of CocosNode. As you can see the drawing primitives aren't CocosNode objects. They are just helper functions that let's you draw basic things like: points, line, polygons and circles.

Answering

TIP: Don't draw your stuff outide the "draw" method. Otherwise it wont get transformed.

TIP: If you want to rotate/translate/scale a circle or any other "primtive", you can do it by rotating the node. eg: self.rotation = 90;